June 18, 2010 at 11:03 PM by Dr. Drang
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 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.
- Speed. I haven’t done any formal timing tests, but
ackis clearly faster.
Ackshows its results in a much clearer format. I must say, though, that I’m not thrilled with some of the colors it uses in the output—maybe those can be changed in the
- Better regular expressions. And by that I mean Perl’s regular expressions.
- Subdirectory search by default. I usually want my searches to walk down into the subdirectories but am always forgetting to turn on
grep’s recursive search option (
-r), so having recursive search as the default is a big help.
- No searching in revision control subdirectories. For me, that means the default is to avoid my
ackalso knows to avoid folders named
RCS, and so on.
A couple of
ack’s defaults are not to my liking.
- It doesn’t search in files that it considers “text” files. Since a lot of my searching is in just these kinds of files—mostly Markdown—this default works against me.
- It’s searches are case-sensitive. This is no different than
grep’s default, but that doesn’t mean I like having to always use the
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:
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