Bug #642

/etc/bash/color.sh should use "auto", not "yes"

Added by Scott Bertilson over 10 years ago. Updated almost 10 years ago.

Status:Closed Start:03/26/2014
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:Calculate Linux Desktop KDE Spent time: -
Target version:14
Votes: 0

Description

/etc/bash/color.sh
which I assume is derived from:
/var/lib/layman/calculate/profiles/templates/3.1/2_ac_install_merge/app-shells/bash/color.sh
which has:
if ${use_color} ; then
alias ls='ls --color=yes'
alias grep='grep --colour=yes'
alias egrep='egrep --colour=yes'
alias fgrep='fgrep --colour=yes'
alias emerge='emerge --color=y'
alias eix='eix -F'
fi

The fact that all these "grep" aliases force color on by using "yes" instead of "auto" is a very big problem when they are part of a pipeline which later depends upon further matching...it fails because of the escape sequences which set the color.

color.sh - from the template file on my 13.11.1 install (256 Bytes) Scott Bertilson, 03/26/2014 11:08 pm

example.txt (348 Bytes) Scott Bertilson, 03/28/2014 01:27 am

History

Updated by Mikhail Hiretsky over 10 years ago

Grep in script work correctly, because color.sh is used only for interactive bash.

/etc/bash/bashrc

18 if [[ $- != *i* ]] ; then
19     # Shell is non-interactive.  Be done now!
20     return
21 fi
...
86 
87 source /etc/bash/color.sh

Please give example with wrong processing scripts.

Updated by Scott Bertilson over 10 years ago

The issue here is that commands shouldn't do colorization any time the output of the command is fed to anything but a terminal...you normally don't want color sequences in a file generated using grep or if you're feeding it into a pipeline... That is why /etc/bash/bashrc (if colors are enabled) sets these aliases:
alias ls='ls --color=auto'
alias grep='grep --colour=auto'
alias egrep='egrep --colour=auto'
alias fgrep='fgrep --colour=auto'

My example actually involves the "ls" command, but the same issue applies to grep - I've had the problem with both commands, just happened to find the "ls" instance and can't seem to find the "grep" instance:
$ ls | egrep -v ''
bin
boot
dev
etc
home
lib
lost+found
mnt
opt
proc
root
run
sbin
sys
tmp
usr
var
$ ls --color=no | egrep -v '
(home|dev|sys|proc)'
bin
boot
etc
lib
lost+found
mnt
opt
root
run
sbin
tmp
usr
var
$ ls --color=auto | egrep -v '^(home|dev|sys|proc)'
bin
boot
etc
lib
lost+found
mnt
opt
root
run
sbin
tmp
usr
var

Please note the difference in the lists.

I definitely understand the desire to have color when I'm feeding a "grep" or "ls" to "less", but I don't think there is an alternative to manually forcing color on for a pipeline because forcing it always has nasty hidden side effects.

Updated by Scott Bertilson over 10 years ago

My example seems to have gotten really corrupted...trying pasting after pulling it into "vi" and pasting from there....no good.

OK, it is still making a mess of the first ls | egrep and I'm completely mystified as to why. Please use the same egrep for all 3 commands in my first example...it should be identical.

Attaching it instead...that couldn't possibly mess up, right?

Updated by Mikhail Hiretsky over 10 years ago

This is done for colorized output by default to pastebin.calcualte-linux.org (command wgetpaste). You can change /etc/bash/color.sh by clt template.

Updated by Scott Bertilson over 10 years ago

Have to say ARRRGH because this really breaks the Unix/Linux pipeline paradigm.

Is colorization that important for things posted to pastebin? There must be a less invasive way to accomplish this.

Updated by Mikhail Hiretsky over 10 years ago

We have kept colorized by default for emerge and eix only (grep and ls will be work as early). Updates will be coming soon.

Updated by Scott Bertilson over 10 years ago

Thanks, that's probably a workable alternative - I don't know of any instance where I'd try to pass the output of emerge or eix through a pipeline to some other program.

Regarding fixing this via templates...I must not be looking in the right place because although I've found stuff talking about variables in templates, I haven't found anything that seems to explain where to find whatever template I would need to change to modify or eliminate color.sh.

Updated by Alexander Tratsevskiy almost 10 years ago

  • Status changed from New to Closed

Also available in: Atom PDF

Thank you!