Last Updated: February 25, 2016
·
620
· markm

Rainbow Grep!

Put this in your .bashrc or .bash_profile for a new grep colour each time it's run.

export GREP_OPTIONS='--color=auto'
grep_path=$(which grep)

function grep() {
    # change the colour for next time
    export GREP_COLOR="1;$(( $RANDOM % 6 + 31 ))"
    # and run the usual grep with the args provided
    $grep_path "$@"
}

Easy :)