]> code.delx.au - gnu-emacs-elpa/blob - gist-git-grep.el
multishell - flesh out history provisions, including deletion.
[gnu-emacs-elpa] / gist-git-grep.el
1 ;; From https://gist.github.com/offby1/1240799
2
3 ;; There's something similar (but fancier) in vc-git.el: vc-git-grep
4
5 ;; -I means don't search through binary files
6
7 ;; --no-color, oddly enough, is required to allow emacs to colorize the output
8
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'."
12 :type 'string)
13
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."
16 :type 'directory
17 )
18
19 (when (require 'vc-git nil t)
20
21 ;; Uncomment this to try out the built-in-to-Emacs function.
22 ;;(defalias 'git-grep 'vc-git-grep)
23
24 (defun git-grep (command-args)
25 (interactive
26 (let ((root (vc-git-root default-directory)))
27 (when (not root)
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): "
32 (format (concat
33 "cd %s && "
34 "%s -e %s")
35 root
36 git-grep-switches
37 (let ((thing (and
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.
42 buffer-file-name
43 (thing-at-point
44 'symbol))))
45 (or (and thing (progn
46 (set-text-properties 0
47 (length thing)
48 nil thing)
49 (shell-quote-argument
50 (regexp-quote thing))))
51 "")))
52 'git-grep-history))))
53 (let ((grep-use-null-device nil))
54 (grep command-args))))
55
56 (provide 'gist-git-grep)