Last active
February 21, 2021 23:53
-
-
Save hgwr/0294ca639f9f1445b35cb93ec7d73531 to your computer and use it in GitHub Desktop.
git-grep - a grep-find variant
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
;; grep-find | |
(when (file-exists-p "/usr/bin/egrep") | |
(setq grep-command "egrep -n -i ") | |
(setq grep-find-command "find . -type f \! -path '*/node_modules/*' \! -path '*/build/coverage/*' \! -path '*/public/*' \! -path '*/vendor/bundle/ruby/*' \! -path '*/.git/*' \! -path '*/.svn/*' \! -path '*/tmp/*' \! -path '*/log/*' \! -name '*~' -print0 | xargs -0 egrep -I -n -i ")) | |
(require 'git-grep) |
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
;;; git-grep.el --- run `grep grep -n | cat' and display the results -*- lexical-binding:t -*- | |
(require 'grep) | |
(setq git-grep-find-command "git grep -i -n | cat") | |
;;;###autoload | |
(defun git-grep (command-args) | |
"Run grep via find, with user-specified args COMMAND-ARGS. | |
Collect output in the \"*grep*\" buffer. | |
While find runs asynchronously, you can use the \\[next-error] command | |
to find the text that grep hits refer to. | |
This command uses a special history list for its arguments, so you can | |
easily repeat a find command." | |
(interactive | |
(progn | |
(grep-compute-defaults) | |
(if git-grep-find-command | |
(list (read-shell-command "Run find (like this): " | |
git-grep-find-command 'grep-find-history)) | |
;; No default was set | |
(read-string | |
"compile.el: No `git-grep-find-command' command available. Press RET.") | |
(list nil)))) | |
(when command-args | |
(let ((null-device nil)) ; see grep | |
(grep command-args)))) | |
(provide 'git-grep) | |
;;; git-grep.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment