Grep and Subversion

May 16, 2008 at 3:38 PM

A while ago, Grant supplied a nice shell hack for recursively grepping through a subversion enlistment while ignoring the .svn directory contents. This was the solution to a thread about counting the number of occurrences of a given word (HACK, in this case) within your project; the final response did this rather nicely.

I've found myself wanting to needing this more and more: searching for all instances in which a certain method is called, for all uses of a particular phrase, for all uses of a CSS class, et cetera. And like a good programmer, I have consistent trouble actually typing out all of those commands and flags. Whether it's my memory or merely my lazy fingers matters not; I needed this to be encapsulated as a shell script that I could call just like grep.

Here's my condensed version. I know some distributions include an 'rgrep' by default; since that name was available on both of mine, I simply took it. Note that I appended the .sh extension so that I could easily force my web server to spit it out as text/plain — in my actual environment, it's just rgrep, and is stuck into a PATH-friendly directory for easy use.

rgrep.sh

Usage: rgrep <pattern> <directory> <grep arguments>