bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#55641: Using colours with grep


From: goncholden
Subject: bug#55641: Using colours with grep
Date: Sat, 28 May 2022 18:19:25 +0000

------- Original Message -------
On Sunday, May 29th, 2022 at 5:36 AM, Paul Eggert <eggert@cs.ucla.edu> wrote:


> On 5/26/22 20:27, Gary Johnson wrote:
>
> > $ export GREP_COLORS='ms=01:33'
> > $ man grep | grep prevents
> > $ man grep | GREP_COLOR='01;32' grep prevents
> >
> > Now, both results have "prevents" in yellow, which agrees with the
> > man page. However, the OP expected the GREP_COLOR setting on the
> > command line to override the GREP_COLORS setting in the environment,
> > which it doesn't.
>
>
> Thanks, your explanation let me see the problem.
>
> Since GREP_COLOR is deprecated, I doubt whether we should be changing
> grep to support this obsolescent usage in a different way. When it comes
> to obsolescent features, the only thing we're likely to change is to
> remove them entirely (as any change will disrupt somebody...).

I agree on removing GREP_COLOR entirely.  Awk and Sed have convenient ways of 
temporarily changing colours.

sga="$(tput setaf 46)"
sgr="$(tput sgr0)"

sed -r $"s/^==> .* <==$/${sga}&${sgr}/"

Would be a good improvement if one can change the colour temporarily from the 
default.  This would help in sectioning matches, particularly when multiple 
files are involved.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]