December 10, 2007

Posted by John

Tagged search, textmate, and workflow

Older: Book Review: Pro Active Record

Newer: KYTCR Part III: Automating Problem Resolution

Ack, A Code Searcher

ack_highlight_example.jpg

Ack is a tool for programmers similar to grep but made for heterogeneous source code trees. What I was impressed with upon downloading and installing it was the highlighting it does all in the terminal.

I’ve used it a few times searching through rails trunk as TextMate seems to dog when you get a bunch of files in one project. It also prominently displays the file path which you can then copy and open with the mate command.

A few reasons you might want to use ack (from the ack site, there are more there as well):

  • it’s really fast
  • it runs on windows
  • the standalone version has no dependencies so you can throw it in ~/bin
  • searches recursively through directories by default, while ignoring .svn, CVS and other VCS directories
  • let’s you specify file types $ ack --perl pattern

Installation is really easy on a mac. Just grab the standalone version and throw it in ~/bin/ack. Note: make sure that it is executable (chmod u+x) and that ~/bin is in your path. Enjoy.

Update: Ack can now be used in textmate with a bundle

6 Comments

  1. Now all we need is an ack_in_project command for Textmate.

  2. GNU grep has a —color feature that highlights the matching text in the terminal. It’s enabled by default on many GNU/Linux distros. GNU grep also has a recursive option, along with a list of patterns to exclude. You can use the $GREP_OPTIONS environment variable to set defaults for these options.

  3. Also: http://rak.rubyforge.org/

    Basically Ack in Ruby

  4. great find, tnx!

  5. Craig: grep’s recursive options get very tedious when you want to exclude directories. The list of patterns to exclude are also very tedious, and grep won’t look inside the file to determine filetype like ack will.

    Yes, you can do most of what ack does with grep, but why?

    John: Glad you dig ack!

  6. I added erb. Rails 2

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

    to

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

Sorry, comments are closed for this article to ease the burden of pruning spam.

About

Authored by John Nunemaker (Noo-neh-maker), a web developer and programmer who has fallen deeply in love with Ruby. More about John.

Syndication

Feed IconRailsTips Articles - An assortment of howto's and thoughts on Ruby and Rails.

Feed IconRails Quick Tips - Ruby and Rails related links.