<?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 shell</title>
    <link>http://www.robbyonrails.com/articles/tag/shell</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <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>
