I'd like to give some options to magit-grep
running it with option foo
results in
git --no-pager grep -n foo
I'd like to give options to it
git --no-pager grep -n foo (options to include *.html and exclude *.py, etc)
It doesn't have to be magit-grep, what's the best git grep solution in emacs?
magit-grep
(magit-define-command grep (&optional pattern)
(interactive)
(let ((pattern (or pattern
(read-string "git grep: "
(shell-quote-argument (grep-tag-default))))))
(with-current-buffer (generate-new-buffer "*Magit Grep*")
(let ((default-directory (magit-get-top-dir)))
(insert magit-git-executable " "
(mapconcat 'identity magit-git-standard-options " ")
" grep -n "
(shell-quote-argument pattern) "\n\n")
(magit-git-insert (list "grep" "--line-number" pattern))
(grep-mode)
(pop-to-buffer (current-buffer))))))
I have removed magit-grep
, as it was just a severely crippled version of rgrep
. vc-git-grep
is actually an improvement, so you should use that. (Nowadays magit-grep
is defined as an alias for the vc command, to avoid disturbing anyone who previously used the magit variant. A classic case of "add features by looking what already exists elsewhere and then remove our code" :-)
One possibility is a combination og git-grep
and git-ls-files
:
git grep ... `git ls-files | grep -- '\.html$'`
But this works only if the output of git-ls-files
does not exceed the maximum command line size on your system (which is a couple of 100K on modern systems).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With