Overlooked ack-grep option

Gotta love the web..

Just a quick update: Andy Lester read the original Combining ack-grep and xargs post and was so kind to point out a much better way to ignore unwanted files while searching i.e.

$ ack-grep --python --ignore-dir=tests/ -C 3 -w 'Message\('

as opposed to

$ find . -name \*.py | grep -v tests/ | xargs ack-grep -C 3 -w 'Message\('
Advertisements

Combining ack-grep and xargs

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 ๐Ÿ™‚