Collecting my attempts to improve at tech, art, and life

Pretty Recursive Grep

Tags: shell tools POST

Does any of this enlighten, entertain, or otherwise please you? Please consider a Tip. Every little bit helps!

I last updated this page

TL;DR Set GREP_OPTIONS='-RI --color=auto'. Or install ack.

I’m looking for TODO entries in source code on a machine that does not have ack installed. It does have GNU grep, though.

Obviously I want to search subdirectories. I can choose between --recursive, -R, or using rgrep on this particular machine.

I am usually searching through source code. I hardly ever want binary files to match. That means --binary-file=without-match or -I.

Finally, I like pretty colors. The --color=auto option makes me happy.

That leaves me with this invocation.

Code Sample
    $ grep --recursive --binary-file=without-match --color=auto 'TODO' .

  

Or maybe the short form would be easier.

Code Sample
    $ rgrep -I --color=auto 'TODO' .

  

Probably smartest to look at what environment variables I could set up in order to skip remembering this stuff at all.

Code Sample
    export GREP_OPTIONS='-RI --color=auto'
  

Pop that in my .bashrc and I’m set.

Code Sample
    $ grep 'TODO' .

  

All right. Back to work.