4 ms·
I use find and grep a lot in code repos, so I came up with this bash function: alias filter_repos_z="grep -ZzEv '/tags|/\.hg/|/\.svn/|/\.git/|/\.repo/|\.o$
by ansible 4y ago
I use find and grep a lot in code repos, so I came up with this bash function:
alias filter_repos_z="grep -ZzEv '/tags|/\.hg/|/\.svn/|/\.git/|/\.repo/|\.o$|\.o\.cmd$|\.depend|\.map$|\.dep$|\.js$|\.html$'"
function findxgrep()
{
find . -type f -print0 | filter_repos_z | xargs -0 grep --color=auto "${@}" | grep -v "^Binary file" | sed 's/^\.\///' | less -F
}
The "${@}" is the critical bit that allows me to pass arguments like -i to grep. The grep, find and xargs commands all support using a NULL as a file separator instead of whitespace.
- dstarh 4y agoEver used ack?
- ansible 4y agoNo, but thanks for pointing out its existence. Homepage: https://beyondgrep.com/ https://beyondgrep.com/
- Beltalowda 4y agothe_silver_searcher and ripgrep are similar (and inspired by Ack). I switched from ack to the_silver_searcher years ago as it's quite a bit faster (or was at the time anyway, not sure how fast Ack is now), and then to ripgrep because it has the -g option (only search files that match a pattern) that's handy sometimes.