Thursday, December 6, 2007

Ignoring .svn directories with emacs' eshell grep

I'm an emacs user. In the morning I fire up emacs and right away open up an eshell buffer. I prefer the eshell (M-x eshell) over the normal shell buffer due to its little perks like:

dylan:~/one/two/three/four/five$ cd .....
dylan:~/one

i.e.:

cd ... = cd ../..
cd .... = cd ../../..

It's the little things :).

Also, I like how when I'm in an eshell buffer and run grep, it opens the results in a new buffer and I can continue with whatever I'm doing.

One thing that has been annoying me for a while, however, was that when I ran grep -r in an eshell buffer it would also search through .svn directories, giving me a lot of crud in my results. In a normal bash shell I got around this by adding this line to my ~/.bash_aliases file:

alias grep="grep --exclude=\*.svn\*"

But that didn't work in eshell, since it's not really a bash shell. Luckily, after looking around a little, I found instructions on how to do aliases in eshell. I added a file called ~/.eshell/alias with the following contents:

alias grep grep --exclude=\*.svn\* $*

After killing and reopening my eshell, all is good! No more .svn directories in my greps. You'll notice that the syntax for the aliasing in eshell is similar, but not equal to the bash syntax. It seems you don't need the '=' or the quotes, and also you need to explicitly reference the args with the '$*'.