Created
August 5, 2015 07:08
-
-
Save keegancsmith/867073f407357aea0f26 to your computer and use it in GitHub Desktop.
M-x rgrep, but using git grep from the top-level git dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; M-x rgrep, but using git grep from the top-level git dir. | |
;; Based on http://stackoverflow.com/questions/25633490/how-can-i-use-m-x-rgrep-with-the-git-grep-command-in-emacs | |
(defcustom git-grep-command "git --no-pager grep --no-color --line-number <C> <R> | sed 's|^|./|'" | |
"The command to run with M-x git-grep.") | |
(defun git-grep (regexp) | |
"Search for the given regexp using `git grep' in the current directory." | |
(interactive "sRegexp: ") | |
(unless (boundp 'grep-find-template) (grep-compute-defaults)) | |
(let ((old-command grep-find-template)) | |
(grep-apply-setting 'grep-find-template git-grep-command) | |
(rgrep regexp "*" (car (process-lines "git" "rev-parse" "--show-toplevel"))) | |
(grep-apply-setting 'grep-find-template old-command))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment