Skip navigation

Ah! I so wanted this in the tip of my fingers that felt really good writing the small elisp code to insert the find command I use the most in shell. See how the insertion bar also gets in place for conveniently start typing in between the quotes.

(set-register ?x "find . -type f -exec grep -i '' /dev/null {} + | awk '!/svn|htdocs/'")
(defalias 'x
(read-kbd-macro "M-x insert-register RET x C-u 30 M-x forward-char "))
(global-set-key [C-S-f10] 'x)

It’s now part of my .emacs file

About these ads

4 Comments

  1. There are better ways to accomplish this. e.g.:

    (defun insert-find-command ()
    (interactive)
    (save-excursion (insert “find . -type f -exec grep -i ” /dev/null {} + | awk ‘!/svn|htdocs/’”)
    (re-search-forward “‘”))

    (define-key shell-mode-map [C-S-f10] ‘insert-find-command)

    You could also use abbrevs or yasnippet. But your best option is probably:

    (define-key (current-global-map) [C-S-f10] ‘rgrep)

  2. Ian, thank you for your suggestions.
    I knew mine was sort of hackish (kind of non-conventional and straight-forward). I am surprised about rgrep, which I didn’t know about, very promising. And didn’t even heard about yasnippet. Thanks for pointing me to those directions.

  3. Emacs 23 will include a new package called ‘find-cmd.el’ that can be used to build find commands using lisp syntax.

    Here’s the example from the source file’s Commentary section:

     (find-cmd '(prune (name ".svn" ".git" ".CVS"))
               '(and (or (name "*.pl" "*.pm" "*.t")
                         (mtime "+1"))
                     (fstype "nfs" "ufs"))))
    
  4. What I do instead is this:

    (setq grep-find-command
    ‘(“find . \\( -name ‘*.log’ -o -name ‘.svn’ -o -name ‘.git’ -o -name ‘CVS’ -o -name ‘TAGS’ -o -name ‘*~’ -o -name ‘*.class’ -o -name ‘*.[wj]ar’ -o -name target -o -name javadoc \\) -prune -o -type f -print0 | xargs -0 grep -H -n “. 225))

    (global-set-key “\C-c2″ ‘grep-find)

    This way, the output goes into a *grep* buffer which has lots of nifty commands for moving between hits.


One Trackback/Pingback

  1. [...] demonstrates some emacs lisp that inserts a commonly used find command in a shell buffer. And Ian Eure has a great follow-up [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: