Robby on Rails: Get to Know a Gem: Rakthoughts.sort_by{|t| t[:topic]}.collect tag:www.robbyonrails.com,2005:TypoTypo2007-12-11T11:11:48-05:00Robby Russellurn:uuid:ae4ad314-4ef2-4c9d-9388-152a1d7c956c2007-12-11T11:10:00-05:002007-12-11T11:11:48-05:00Get to Know a Gem: Rak<p>A few months ago, I posted about an article that showed you <a href="http://www.robbyonrails.com/articles/2007/10/06/spice-up-your-terminal-with-colored-grep-pattern-results">how to colorize your grep search results</a>. Since then, I’ve heard people talking about <a href="http://petdance.com/ack/">ack</a>, which describes itself as…</p>
<blockquote>
<p>“a tool like grep, aimed at programmers with large trees of heterogeneous source code.”</p>
</blockquote>
<p>It’s written in Perl, which is fine and dandy… but before I installed it, I heard that there was a Ruby version named <a href="http://rak.rubyforge.org/">rak</a>, which describes itself as…</p>
<blockquote>
<p>“a grep replacement in pure Ruby. It accepts Ruby syntax regular expressions and automatically recurses directories, skipping .svn/, .cvs/, pkg/ and more things you don’t care about. “</p>
</blockquote>
<p>Sounds great. Let’s see what this thing can do.</p>
<h2>Installing rak</h2>
<p>Daniel Lucraft, the author of rak, was kind enough to package it up as a Rubygem. So, all we have to do is install it via <code>gem install rak</code>.</p>
<pre><code>
> sudo gem install rak
Password:
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rak-0.8.0
Installing ri documentation for rak-0.8.0...
Installing RDoc documentation for rak-0.8.0...
~ >
</code></pre>
<p>Great, let’s move on.</p>
<h2>Using rak</h2>
<p>Now that it’s installed, we can use Rak by typing <code>rak</code> from the command line. You’d typically want to run this from within the root of your application.</p>
<p>For example, basic usage would look like the following.</p>
<code>$ rak search-pattern</code>
<p>In my first test, I ran <code>rak README</code>.</p>
<p><img src="http://myskitch.com/robbyrussell/rak_output_1-20071211-083456.jpg" alt="" /></p>
<p>Immediately, I see a greater advantage to <code>rak</code> over using <code>grep</code> and that’s because it’s giving me line numbers for free, which takes remembering a few extra options with grep.</p>
<p>Like <code>grep</code>, we can specify a specific path to search with. For example, we use a view helper named <code>link_to_unimplemented</code> to help us track actions that aren’t implemented yet. Looking at a current project, I can run <code>rak link_to_unimplemented app/views</code> and produce the following results.</p>
<p><img src="http://myskitch.com/robbyrussell/terminal__less__160x49-20071211-085748.jpg" alt="" /></p>
<p>I’m going to keep playing with it, but wanted to help get the word out. If you have any tips on using it, please share them in the comments. :-)</p><p>A few months ago, I posted about an article that showed you <a href="http://www.robbyonrails.com/articles/2007/10/06/spice-up-your-terminal-with-colored-grep-pattern-results">how to colorize your grep search results</a>. Since then, I’ve heard people talking about <a href="http://petdance.com/ack/">ack</a>, which describes itself as…</p>
<blockquote>
<p>“a tool like grep, aimed at programmers with large trees of heterogeneous source code.”</p>
</blockquote>
<p>It’s written in Perl, which is fine and dandy… but before I installed it, I heard that there was a Ruby version named <a href="http://rak.rubyforge.org/">rak</a>, which describes itself as…</p>
<blockquote>
<p>“a grep replacement in pure Ruby. It accepts Ruby syntax regular expressions and automatically recurses directories, skipping .svn/, .cvs/, pkg/ and more things you don’t care about. “</p>
</blockquote>
<p>Sounds great. Let’s see what this thing can do.</p>
<h2>Installing rak</h2>
<p>Daniel Lucraft, the author of rak, was kind enough to package it up as a Rubygem. So, all we have to do is install it via <code>gem install rak</code>.</p>
<pre><code>
> sudo gem install rak
Password:
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rak-0.8.0
Installing ri documentation for rak-0.8.0...
Installing RDoc documentation for rak-0.8.0...
~ >
</code></pre>
<p>Great, let’s move on.</p>
<h2>Using rak</h2>
<p>Now that it’s installed, we can use Rak by typing <code>rak</code> from the command line. You’d typically want to run this from within the root of your application.</p>
<p>For example, basic usage would look like the following.</p>
<code>$ rak search-pattern</code>
<p>In my first test, I ran <code>rak README</code>.</p>
<p><img src="http://myskitch.com/robbyrussell/rak_output_1-20071211-083456.jpg" alt="" /></p>
<p>Immediately, I see a greater advantage to <code>rak</code> over using <code>grep</code> and that’s because it’s giving me line numbers for free, which takes remembering a few extra options with grep.</p>
<p>Like <code>grep</code>, we can specify a specific path to search with. For example, we use a view helper named <code>link_to_unimplemented</code> to help us track actions that aren’t implemented yet. Looking at a current project, I can run <code>rak link_to_unimplemented app/views</code> and produce the following results.</p>
<p><img src="http://myskitch.com/robbyrussell/terminal__less__160x49-20071211-085748.jpg" alt="" /></p>
<p>I’m going to keep playing with it, but wanted to help get the word out. If you have any tips on using it, please share them in the comments. :-)</p>