Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
darn you gentoo, stop colorizing grep!
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
danboston
n00b
n00b


Joined: 17 Nov 2016
Posts: 47

PostPosted: Wed Jan 11, 2017 1:46 pm    Post subject: darn you gentoo, stop colorizing grep! Reply with quote

Recently, my system has begun to highlight grep matches in bold red. I'd like it to not do this.

I've found several guides to turn this feature on, such as :
https://debian-administration.org/article/460/grep_highlighting_matches_in_color
but the information has not helped me to go the other way, to disable this.

The man page for grep mentions setting the environment variables GREP_COLOR and GREP_COLORS to "never" but, as is often the case with environment variables, doing this has no effect.

My .bash_rc has aliases to activate this feature, but they are commented out, and have always been, so that's not the culprit.

I'm going to guess that the /youll_never_guess_this_path/youll_never_guess_this_name.conf is the problem but I've yet to ascertain its name nor location.

Can I have a clue please?
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Wed Jan 11, 2017 1:51 pm    Post subject: Reply with quote

Not too surprisingly the man page is fully informative on this topic. You could either add
Code:
alias grep='grep --color=never'
to your .bashrc or else place GREP_COLORS in your environment specifying no colorization. Reading The Fine Manual is recommended. :wink:

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
danboston
n00b
n00b


Joined: 17 Nov 2016
Posts: 47

PostPosted: Wed Jan 11, 2017 4:00 pm    Post subject: Reply with quote

John R. Graham wrote:
Not too surprisingly the man page is fully informative on this topic. You could either add
Code:
alias grep='grep --color=never'
to your .bashrc or else place GREP_COLORS in your environment specifying no colorization. Reading The Fine Manual is recommended. :wink:

- John

The manual ("man grep") that I mentioned reading in my initial post? The GREP_COLORS variable that I'd already tried and mentioned trying? Reading the fine post entirely is also recommended. ;)

Anyway. In my further researches, I've discovered some interesting things. Typign "alias" by itself lists all aliases. Typing "env" by itself lists all environment variables. Seems something was already defining grep to use colors (as suspected). Example: alias grep='alias --color=auto'. I was hesitant about [re]aliasing grep, since I'd probably get a nested grep, the equivalent of "grep --color=never --color=auto". The results would be indeterminate, right? Well, I tried it anyway. In my ~/.bashrc :
Code:

alias egrep='egrep --colour=never'
alias fgrep='fgrep --colour=never'
alias grep='grep --colour=never'

Started a new term. Grepped some things. No more red highlight. It's not a proper fix-the-oroginal-cause solution but it's an acceptable kludge. :)

Thank you, everyone, for the replies.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Wed Jan 11, 2017 4:04 pm    Post subject: Reply with quote

Setting GREP_COLORS to "ms=:mc=:sl=:cx=:fn=:ln=:bn=:se=", which is a technique that can be divined from the Fine Manual, works. The manual also states that "ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36" is the default in the absence of the environment variable. Sorry if I was unnecessarily obscure, but it was obvious you had some reading to do.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Wed Jan 11, 2017 9:58 pm    Post subject: Reply with quote

danboston wrote:
I was hesitant about [re]aliasing grep, since I'd probably get a nested grep, the equivalent of "grep --color=never --color=auto". The results would be indeterminate, right?

danboston ... aliases don't work that way, if you redefine then this is what the alias is set to:

Code:
% alias foo="echo foo"
% foo
foo
% alias foo="echo bar"
% foo
bar

Anyhow, since the depreciation of GREP_OPTIONS I have the following:

~/.zprofile:
export GREP_COLOR='00;38;5;226'
export GREP_OPTIONS="--color=auto \
 --directories=skip \
 --binary-files=without-match \
 --exclude=\*.swp \
 --exclude=\*.pyc \
 --exclude=\*.zwc\* \
 --exclude=.zcompdump\* \
 --exclude-dir=.git \
 --exclude-dir=.svn"

~/.zshrc:
for i (grep egrep fgrep) alias $i="$i $GREP_OPTIONS" ;
alias zgrep='zgrep --color=auto'
unset GREP_OPTIONS

I would imagine the following would work for bash (untested)

~/.bashrc:
export GREP_OPTIONS="--color=never \
 --directories=skip \
 --binary-files=without-match \
 --exclude=\*.swp \
 --exclude=\*.pyc \
 --exclude-dir=.git \
 --exclude-dir=.svn"

for i in grep egrep fgrep ; do alias $i="$i $GREP_OPTIONS" ; done
alias zgrep='zgrep --color=never'
unset GREP_OPTIONS

HTH & best ... khay
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Wed Jan 11, 2017 11:45 pm    Post subject: Reply with quote

Comment out the alias in /etc/bash/bashrc.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum