Ack 2.0: Written in Perl, Useful With Ruby
20 Apr 2013Ack is an open source command line tool that lets developers search large trees of source code very quickly. If you are looking for a method definition in a haystack of files, Ack will find that needle for you. Many devs regard Ack as a replacement for grep.
The Elmhurst ChicagoRuby meetings are always a source of unexpected learning. Today ChicagoRuby welcomed Andy Lester, creator of Ack. Andy released Ack 2.0 two days ago. He shared some of the latest features in an impromptu demo.
Why Ack?
Have you ever been working on a project, only to be interrupted when you need to look for something? It could be a method name, a variable declaration, or a string of text in a comment. A minor distraction costs you the time it takes to search plus the time required to re-focus.
All of us are more productive when we stay in the zone. Ack helps devs to maintain focus and thereby produce better results.
First, Install Perl
Ack requires the Perl programming language. Perl comes pre-installed on Mac OS X and most Linux distros. If you’re running on a ‘nix platform, you probably have Perl already.
Windows installations are beyond the scope of this article. If you’re running Windows, you might consider a Linux VM for Ruby and Rails-related work.
Installing Ack on Mac OS X
Installing Ack is so easy that it almost feels wrong: Grab Ack in a single Perl file and drop it in your ~/bin/
directory. That’s it.
Ack can also be installed via Homebrew, but I prefer the drop it in ~/bin installation since everything is contained in one file. Here’s a more detailed version of the steps:
- If you don’t have one already, create
~/bin/
as a subdirectory of your home directory. - Grab a the single-file copy of Ack from http://beyondgrep.com/
- Drop the single-file copy of Ack into a file called
~/bin/ack
- Make sure that
$HOME/bin:
appears at the beginning of your$PATH
environment variable.
At this point you should be running Ack v2.0 or later. To verify:
~/bin$ ack --version
ack 2.02 (git commit f3c8827)
Running under Perl 5.12.4 at /usr/bin/perl
Copyright 2005-2013 Andy Lester.
This program is free software. You may modify or distribute it
under the terms of the Artistic License v2.0.
~/bin$
Installation complete. Now, let’s take Ack for a spin.
Using Ack at the Command Line
For a sample project, let’s use demo_app
from Michael Hartl’s Ruby on Rails Tutorial. Imagine that you want to find every file in the project that references user_id
. How would you do that?
Fast, clear, and highlighted in color. Bonus: If you’re a Vim user, try ack.vim if you want to run Ack without leaving your editor.
The Bottom Line
Ack helps devs to find things quicker without leaving the zone. Try it!