[emacs-berlin] git grep

Tilmann Singer tils at tils.net
Wed Oct 29 21:11:55 CET 2014

For Andi - my very hackish local git grep setup, feedback welcome:


Apparantly it depends on magit to find the root folder, but I'm sure
that could be done more elegantly. Also, no idea if the setenv PAGER
call is necessary.


(defun grep-project (q)
  "Search using git grep"
  (interactive (list
                (read-from-minibuffer "git grep: "
                                      (if (region-active-p)
                                          (buffer-substring-no-properties (region-beginning) (region-end))
                                      nil nil 'grep-project)))
  (let ((command
  "cd " (magit-get-top-dir default-directory) " && "
  "git grep --untracked -i -n --no-color --full-name '" q "' -- ")))
  (add-to-history 'grep-find-history command)
  (grep command)
(setenv "PAGER" "cat")
(global-set-key [(f3)] 'grep-project)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://mailb.org/pipermail/emacs-berlin/attachments/20141029/a811d9c2/attachment.sig>

More information about the emacs-berlin mailing list