wcgrep: grep your working copy more efficiently

or ‘do better than `| grep -v svn`’

Until somewhat recently this is how I grepped my wc:

grep -rn search_string . |grep -v svn
(21m41s — lots of source, lots of images — ~24,000)

blech.

It was getting slower, image directories fill up in a busy site.

I tried to speed it up with:
grep -rn session_start . --exclude='*.jpg' --exclude='*.gif'|grep -v svn
(51s)

Pretty decent improvement with this, but ugly as sin.

Even with ctrl+r reverse history searching in bash, that’s a pain.

Cleaner but longer:
grep -rnI search_string . |grep -v svn
(3m9s)
-I is the same as --binary-files=without-match — it assumes binary files are non-matching.
Hmm, I figured this would take less time, I’m guessing the time is in grep still touching the files to determine if they’re binary or not.

And the best:
wcgrep search_string
(16s)

it can even take grep params directly:
wcgrep -i search_string

This definitely speeds up my svn wc grepping (until I switch to git =).

Cheers!