Skip to content

Instantly share code, notes, and snippets.



Last active Feb 21, 2021
What would you like to do?
git-grep - a grep-find variant
;; 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)
;;; 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")
(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."
(if git-grep-find-command
(list (read-shell-command "Run find (like this): "
git-grep-find-command 'grep-find-history))
;; No default was set
"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