Is there an equivalent to git grep
in Mercurial? That is, search for text only in the working copy, in files tracked by Mercurial. (hg grep
searches the repository history.)
hg files "set:grep(regex_goes_here) and not binary()"
See filesets documentation for more information. Briefly, this prints all tracked files which match the given regex and are not binary files (do not contain NUL bytes).
Add this alias to ~/.hgrc
:
[alias]
grepcwd = ! $HG grep -r 'reverse(::.)' "$1" .
Then use hg grepcwd foobar
the same way you would use git grep foobar
.
Original source: http://www.emilsit.net/blog/archives/git-is-more-usable-than-mercurial/
An upgrade to Kevins answer:
Sadly hg files "set:grep(regex_goes_here) and not binary()"
does only return the file but does not allow to peak into the found line like git grep
does.
So I created an alias. Put the following lines into your ~/.bashrc
:
alias hggrep='f(){
FILES_HG=$(hg files "set:grep(\"$1\") and not binary()")
for file_grep in $FILES_HG; do
grep --color -Hn "$1" "$file_grep"
done
unset -f f
}
f'
Use like this: hggrep foobar
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