Gotta love the command line..
I use ack-grep a lot and really, really like it. Kudos to the author and to the maintainer who takes care of the ubuntu package
Sometimes though I was missing grep‘s --exclude feature that allows me to ignore certain paths while searching.
There are occasions where I e.g. want to see calls to a certain function in the code base but I am not interested in tests. Today I found an (embarrassingly) easy way to get that behaviour using xargs:
$ find . -name \*.py | grep -v tests/ | xargs ack-grep -C 3 -w 'Message\('
The snippet above first accumulates the paths of interests, then filters them and finally lets ack-grep loose on them.
Ta-da! There you go
Advertisement
April 27, 2010 at 5:06 pm |
Let ack do the searching for the python for you.
ack –python –ignore-dir=tests/ -C 3 ‘Message\(‘
I added the –python (and other languages) specifically to avoid the “find . -name” stuff.
April 27, 2010 at 5:18 pm |
Oh wow! I totally missed the ‘–ignore-dir’ command line arg
That will do the job in the vast majority of the cases, I agree.
Thanks for the pointer!
April 27, 2010 at 6:04 pm |
Yes, but even better, –python! Or –nopython! Do ack –help-types
April 28, 2010 at 4:41 am |
@andy: gotcha, “ack –python –ignore-dir=tests/ -C 3 ‘Message\(‘” is the way to go. Thanks again!
April 27, 2010 at 8:55 pm |
Isn’t ack-grep package a 1:1 copy from Debian?
April 28, 2010 at 4:38 am |
@lara yes, all ubuntu packages are based on debian and ack-grep is no exception. So, kudos to the debian package maintainer as well
April 28, 2010 at 4:43 am
err .. that should probably read: “_almost_ all ubuntu packages are based on debian..”
April 28, 2010 at 7:26 am |
[...] Muharem Hrnjadovic Cool ideas revolving around computers and programming « Combining ack-grep and xargs [...]