<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Robby on Rails: Tag grep</title>
    <link>http://www.robbyonrails.com/articles/tag/grep</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>Get to Know a Gem: Rak</title>
      <description>&lt;p&gt;A few months ago, I posted about an article that showed you &lt;a href="http://www.robbyonrails.com/articles/2007/10/06/spice-up-your-terminal-with-colored-grep-pattern-results"&gt;how to colorize your grep search results&lt;/a&gt;. Since then, I&amp;#8217;ve heard people talking about &lt;a href="http://petdance.com/ack/"&gt;ack&lt;/a&gt;, which describes itself as&amp;#8230;&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;a tool like grep, aimed at programmers with large trees of heterogeneous source code.&amp;#8221;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;It&amp;#8217;s written in Perl, which is fine and dandy&amp;#8230; but before I installed it, I heard that there was a Ruby version named &lt;a href="http://rak.rubyforge.org/"&gt;rak&lt;/a&gt;, which describes itself as&amp;#8230;&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;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&amp;#8217;t care about. &amp;#8220;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Sounds great. Let&amp;#8217;s see what this thing can do.&lt;/p&gt;


	&lt;h2&gt;Installing rak&lt;/h2&gt;


	&lt;p&gt;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 &lt;code&gt;gem install rak&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
   &amp;gt; 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...
  ~ &amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great, let&amp;#8217;s move on.&lt;/p&gt;


	&lt;h2&gt;Using rak&lt;/h2&gt;


	&lt;p&gt;Now that it&amp;#8217;s installed, we can use Rak by typing &lt;code&gt;rak&lt;/code&gt; from the command line. You&amp;#8217;d typically want to run this from within the root of your application.&lt;/p&gt;


	&lt;p&gt;For example, basic usage would look like the following.&lt;/p&gt;


&lt;code&gt;$ rak search-pattern&lt;/code&gt;

	&lt;p&gt;In my first test, I ran &lt;code&gt;rak README&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/rak_output_1-20071211-083456.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Immediately, I see a greater advantage to &lt;code&gt;rak&lt;/code&gt; over using &lt;code&gt;grep&lt;/code&gt; and that&amp;#8217;s because it&amp;#8217;s giving me line numbers for free, which takes remembering a few extra options with grep.&lt;/p&gt;


	&lt;p&gt;Like &lt;code&gt;grep&lt;/code&gt;, we can specify a specific path to search with. For example, we use a view helper named &lt;code&gt;link_to_unimplemented&lt;/code&gt; to help us track actions that aren&amp;#8217;t implemented yet. Looking at a current project, I can run &lt;code&gt;rak link_to_unimplemented app/views&lt;/code&gt; and produce the following results.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/terminal__less__160x49-20071211-085748.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;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. :-)&lt;/p&gt;
</description>
      <pubDate>Tue, 11 Dec 2007 11:10:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:ae4ad314-4ef2-4c9d-9388-152a1d7c956c</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/12/11/get-to-know-a-gem-rak</link>
      <category>Ruby</category>
      <category>Programming</category>
      <category>gems</category>
      <category>rubyforge</category>
      <category>rak</category>
      <category>grep</category>
      <category>terminal</category>
      <category>unix</category>
      <category>tip</category>
      <category>development</category>
      <category>code</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Spice up your Terminal with colored grep pattern results</title>
      <description>&lt;p&gt;Earlier, I came across a post by Garry Dolley, which he shows how to acheive &lt;a href="http://scie.nti.st/2007/7/18/colorized-grep-matches"&gt;colorized grep matches&lt;/a&gt; in bash. I recall having color matches when I used to use Linux on a daily basis as my primary work environment, but haven&amp;#8217;t gotten around to setting this up on my MacBook, which is where I do almost all of my development work.&lt;/p&gt;


	&lt;h2&gt;Before&lt;/h2&gt;


	&lt;p&gt;If you don&amp;#8217;t already have colors, a grep in your terminal might look something like the following screenshot.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/terminal_sans_colors-20071006-104657.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;While, I have a very small output here, this gets much crazier when you&amp;#8217;re using &lt;code&gt;egrep&lt;/code&gt; across an entire project. It&amp;#8217;s hard to scan through all of the results for the inline pattern matches.&lt;/p&gt;


	&lt;p&gt;So, taking Garry&amp;#8217;s suggestion (for &lt;code&gt;bash&lt;/code&gt;), I did something similar with my favorite shell, &lt;a href="http://en.wikipedia.org/wiki/Zsh"&gt;Z shell&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Add the following to your &lt;code&gt;~/.zshrc&lt;/code&gt; file to begin experimenting with the colors.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  export GREP_OPTIONS='--color=auto' 
  export GREP_COLOR='1;36'
&lt;/code&gt;&lt;/pre&gt;

	&lt;h2&gt;After&lt;/h2&gt;


	&lt;p&gt;With the new variables defined in my &lt;code&gt;.zshrc&lt;/code&gt;, I can now start to see colors showing up in my grep results.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/grep_with_colors-1-20071006-104732.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Pretty cool, huh?&lt;/p&gt;


	&lt;h2&gt;Variants&lt;/h2&gt;


	&lt;p&gt;To save you the trouble of trying tons of combinations yourself, which I suspect you&amp;#8217;ll do anyways, here are some other variants.&lt;/p&gt;


	&lt;h3&gt;Blinking&lt;/h3&gt;


	&lt;p&gt;If you change the first number in &lt;code&gt;GREP_COLOR&lt;/code&gt; to &lt;strong&gt;5&lt;/strong&gt;, you&amp;#8217;re matches will &lt;blink&gt;&lt;strong&gt;blink&lt;/strong&gt;&lt;/blink&gt;!&lt;/p&gt;


	&lt;p&gt;You&amp;#8217;ll have to experiment with this yourself as I&amp;#8217;m not going to make a video for you. ;-)&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  export GREP_COLOR='5;35'
&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Inverted Colors&lt;/h3&gt;


	&lt;p&gt;You can also invert the colors so that the background color changes on your pattern matches.&lt;/p&gt;


	&lt;p&gt;For example:&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/default-3-20071006-104539.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;To achieve this, you can set the first number in &lt;code&gt;GREP_COLOR&lt;/code&gt; to &lt;strong&gt;7&lt;/strong&gt;.&lt;/p&gt;


	&lt;h3&gt;...and so much more&lt;/h3&gt;


	&lt;p&gt;I decided to write a quick and ugly ruby script to iterate through the color combinations that I was trying.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/coloring_egrep-20071006-104018.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Anyhow, I&amp;#8217;ll leave you on that note. If you figure out how to do any other fun things with grep colors, do let me know. :-)&lt;/p&gt;
</description>
      <pubDate>Sat, 06 Oct 2007 12:43:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:0bc194d2-edc7-4df5-ad4a-298061ef9d9f</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/10/06/spice-up-your-terminal-with-colored-grep-pattern-results</link>
      <category>Programming</category>
      <category>grep</category>
      <category>shell</category>
      <category>unix</category>
      <category>terminal</category>
      <category>egrep</category>
      <category>colors</category>
    </item>
  </channel>
</rss>
