View previous topic :: View next topic |
Author |
Message |
danboston n00b
Joined: 17 Nov 2016 Posts: 47
|
Posted: Wed Jan 11, 2017 1:46 pm Post subject: darn you gentoo, stop colorizing grep! |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10590 Location: Somewhere over Atlanta, Georgia
|
Posted: Wed Jan 11, 2017 1:51 pm Post subject: |
|
|
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.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
danboston n00b
Joined: 17 Nov 2016 Posts: 47
|
Posted: Wed Jan 11, 2017 4:00 pm Post subject: |
|
|
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.
- 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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10590 Location: Somewhere over Atlanta, Georgia
|
Posted: Wed Jan 11, 2017 4:04 pm Post subject: |
|
|
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 |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Wed Jan 11, 2017 9:58 pm Post subject: |
|
|
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 |
|
|
Ant P. Watchman
Joined: 18 Apr 2009 Posts: 6920
|
Posted: Wed Jan 11, 2017 11:45 pm Post subject: |
|
|
Comment out the alias in /etc/bash/bashrc. |
|
Back to top |
|
|
|