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
Tags
.htaccess apache awk bash cat clipboard copy cut cygwin design dot-emacs editor elisp emacs floating-point gnu indentation indenting inspiration keyboard macro mysql oneliner org-mode paste perl php programming range regex regex range sed shell ssh svn sys-admin technology text-editing tips&tricks ubuntu unix vi(m) web web programmers' view wordpress xargsTop Posts
- emacs, indent/unindent region as a block using the tab key
- awk (or cut), printing lines from the nth field on
- how to undefine a key binding in emacs
- disable "Alt+`" hotkeys in Ubuntu 11.10
- heredoc tip, execute mysql commands from shell with multiline scripts or queries
- checkboxes in emacs org-mode
- emacs, navigate back to the positions you visited in the buffer file
- customizing emacs occur
- fetching a set of files or part of a website with wget
4 Comments
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)
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.
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"))))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
[...] demonstrates some emacs lisp that inserts a commonly used find command in a shell buffer. And Ian Eure has a great follow-up [...]