Working As Intended

Adding new file types to "Ack in Project" TextMate bundle

July 7th 2009

If you edit with TextMate, but you haven’t yet installed Ack in Project, you’re missing out. It’s much faster than TextMate’s built-in search. My preferred fork of this bundle is David Lynch’s, which adds a pull down menu of file types to focus your search on.

Ack In Project
Uploaded with plasq's Skitch!

One of the cool things about file types in Ack is that they’re more like buckets of types. Looking in ack-standalone.sh, this is the default mapping for “Ruby” files.

ruby => [qw( rb rhtml rjs rxml erb )]

I wanted to include Haml in that list, so I edited the .sh file and issued a pull request for the change. David wrote back, informing me that these mappings can be modified on the command line so I dug into that a bit deeper.

It turns out that you can modify an existing mapping with Ack’s –type-add switch. In this example, I wanted to include both .haml and .rake files to my “ruby” searches.

--type-add=ruby=.haml,.rake

You can also add a completely new type with –type-set.

--type-set=haml=.haml

Put these in ~/.ackrc with each switch on its own line.

The Ack docs don’t use the equal sign after the switch name, but I found that it’s needed for OS X. No idea why that is, but it seems to work.

Ack in Project will automatically pick up these changes, because it builds the pull-down menu by parsing the output of ack –help=types. This also makes it convenient to see if you’ve set up your .ackrc file properly.

$ ack --help=types
...
    --[no]ruby         .rb .rhtml .rjs .rxml .erb .haml .rake
...

Yay.

blog comments powered by Disqus

Feed Feed