1 ;; From https://gist.github.com/offby1/1240799
3 ;; There's something similar (but fancier) in vc-git.el: vc-git-grep
5 ;; -I means don't search through binary files
7 ;; --no-color, oddly enough, is required to allow emacs to colorize the output
9 (defcustom git-grep-switches
10 "git --no-pager grep --extended-regexp -I -n --ignore-case --no-color"
11 "Switches to pass to `git grep'."
14 (defcustom git-grep-default-work-tree (expand-file-name "~/work/adtrack")
15 "Top of your favorite git working tree. \\[git-grep] will search from here if it cannot figure out where else to look."
19 (when (require 'vc-git nil t)
21 ;; Uncomment this to try out the built-in-to-Emacs function.
22 ;;(defalias 'git-grep 'vc-git-grep)
24 (defun git-grep (command-args)
26 (let ((root (vc-git-root default-directory)))
28 (setq root git-grep-default-work-tree)
29 (message "git-grep: %s doesn't look like a git working tree; searching from %s instead" default-directory root))
30 (list (read-shell-command
31 "Run git-grep (like this): "
38 ;; Don't snarf stuff from the buffer if
39 ;; we're not looking at a file.
40 ;; Perhaps we should also check to see
41 ;; if the file is part of a git repo.
46 (set-text-properties 0
50 (regexp-quote thing))))
53 (let ((grep-use-null-device nil))
54 (grep command-args))))
56 (provide 'gist-git-grep)