Ack

At the end of last week’s post about trusses, I mentioned that I had found an old photo of a roof truss by greping for the word “truss” in a folder of project reports on my work computer. I should not have grep’d; I should have ack’d.

Ack is a Perl script that’s meant to be a replacement of and improvement on the venerable Unix search tool grep. I’d read about ack quite a while ago—there’s a TextMate bundle called Ack in Project that’s well thought of—but kept forgetting to install it. Now that I have it installed, I see some obvious improvements.

A couple of ack’s defaults are not to my liking.

These defaults betray ack’s origins as a programmer’s tool. Programmers usually want to search through their source code and avoid extraneous hits in, say, the documentation files. And most of today’s languages are case-sensitive, so it only makes sense for the default searches to be so as well.

Luckily for me, ack’s defaults can be changed through an .ackrc file in my home directory. Right now my .ackrc has just two lines:

--type=text
--smart-case

The first line tells ack to go ahead and search the text files. The second tells it to do case-insensitive searches unless the search term has a capital letter. The format of the .ackrc is simple: each line represents a command line switch and is written just as if you were adding it to an ack command—there’s no special dotfile syntax.

I’ll probably add more lines to my .ackrc as I learn more about it. For now, I’m just wondering why I didn’t switch from grep earlier.