Closed petdance closed 7 years ago
I'm just commenting in here as I find things:
export GREP_OPTIONS='--color=auto'
(alternately, I use alias grep='grep --color=auto'
)export GREP_COLOR='30;43'
(colors are the same ones as documented for ANSI/VT100 Escape Sequences)export GREP_OPTIONS='--line-number'
export GREP_OPTIONS='-H'
I know this doesn't do the grouping, but I think I'll need to do a bash function for that.
And here's the function:
mygrep () {
GREP_COLOR=${MYGREP_COLOR:-'30;43'} \
/usr/bin/grep -RH --line-number --color=always $* | \
MYGREP_NUMBER_COLOR=${MYGREP_NUMBER_COLOR:-'33;40'} \
MYGREP_FILE_COLOR=${MYGREP_FILE_COLOR:-'31;40'} \
perl -ne 'BEGIN { $lastfile = q{}; }
($file, $line, $match) = split ":", $_, 3;
if ($file ne $lastfile) {
print "\n" if $lastfile ne q{};
print "\e[".$ENV{MYGREP_FILE_COLOR}."m$file\e[0m\n";
$lastfile = $file;
}
print "\e[".$ENV{MYGREP_NUMBER_COLOR}."m$line\e[0m:$match";
' | less -FRX
}
It takes the output of grep with recursion, line numbers and file names always on, and uses a perl almost one-liner to print the filenames in color before the results of the match. The colors default to what I've got ack defaulted to use, but they can be controlled through the MYGREP_COLOR (the color of the matches), MYGREP_FILE_COLOR (the color of the filenames) and MYGREP_NUMBER_COLOR (the color of the line numbers) variables.
GNU doesn't want to make it easy.
While yes one could export
GREP_OPTIONS=-R
but they'll warn because that is deprecated as non-portable. sigh
https://www.gnu.org/software/grep/manual/html_node/Environment-Variables.html#Environment-Variables
They say " Please use an alias or script instead", which means to make grep work differently you have to rename the new behavior.
This issue was moved to petdance/ack3#30
I think a lot of people use ack strictly because of the grouping and the pretty colors. It's trivial to make grep do this and then you don't have to use ack.
Put something in the ack docs that explains how.