The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Spice up your Terminal with colored grep pattern results

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Robby Russell

Posts: 981
Nickname: matchboy
Registered: Apr, 2005

Robby Russell is the Founder & Executive Director PLANET ARGON, a Ruby on Rails development firm
Spice up your Terminal with colored grep pattern results Posted: Oct 6, 2007 12:34 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Robby Russell.
Original Post: Spice up your Terminal with colored grep pattern results
Feed Title: Robby on Rails
Feed URL: http://feeds.feedburner.com/RobbyOnRails
Feed Description: Ruby on Rails development, consulting, and hosting from the trenches...
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Robby Russell
Latest Posts From Robby on Rails

Advertisement

Earlier, I came across a post by Garry Dolley, which he shows how to acheive colorized grep matches in bash. I recall having color matches when I used to use Linux on a daily basis as my primary work environment, but haven’t gotten around to setting this up on my MacBook, which is where I do almost all of my development work.

Before

If you don’t already have colors, a grep in your terminal might look something like the following screenshot.

While, I have a very small output here, this gets much crazier when you’re using egrep across an entire project. It’s hard to scan through all of the results for the inline pattern matches.

So, taking Garry’s suggestion (for bash), I did something similar with my favorite shell, Z shell.

Add the following to your ~/.zshrc file to begin experimenting with the colors.


  export GREP_OPTIONS='--color=auto' 
  export GREP_COLOR='1;36'

After

With the new variables defined in my .zshrc, I can now start to see colors showing up in my grep results.

Pretty cool, huh?

Variants

To save you the trouble of trying tons of combinations yourself, which I suspect you’ll do anyways, here are some other variants.

Blinking

If you change the first number in GREP_COLOR to 5, you’re matches will blink!

You’ll have to experiment with this yourself as I’m not going to make a video for you. ;-)


  export GREP_COLOR='5;35'

Inverted Colors

You can also invert the colors so that the background color changes on your pattern matches.

For example:

To achieve this, you can set the first number in GREP_COLOR to 7.

...and so much more

I decided to write a quick and ugly ruby script to iterate through the color combinations that I was trying.

Anyhow, I’ll leave you on that note. If you figure out how to do any other fun things with grep colors, do let me know. :-)

Read: Spice up your Terminal with colored grep pattern results

Topic: Clear out your old gems... It could save you time and ram... Previous Topic   Next Topic Topic: Web 3.0, the Official Definition.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use