Bug #642

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

Добавил(а) Scott Bertilson больше 10 лет назад. Обновлено почти 10 года назад.

Статус:Closed Начата:26.03.2014
Приоритет:Normal Дата выполнения:
Назначена:- Готовность в %:

0%

Категория:Calculate Linux Desktop KDE Затраченное время: -
Версия:14
Голоса: 0

Описание

/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 байта) Scott Bertilson, Ср, 26 марта 2014, 23:08:51 +0400

example.txt (348 байта) Scott Bertilson, Пт, 28 марта 2014, 01:27:50 +0400

История

Обновлено Mikhail Hiretsky больше 10 лет назад

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.

Обновлено Scott Bertilson больше 10 лет назад

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.

Обновлено Scott Bertilson больше 10 лет назад

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?

Обновлено Mikhail Hiretsky больше 10 лет назад

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.

Обновлено Scott Bertilson больше 10 лет назад

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.

Обновлено Mikhail Hiretsky больше 10 лет назад

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

Обновлено Scott Bertilson больше 10 лет назад

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.

Обновлено Alexander Tratsevskiy почти 10 года назад

  • Параметр Статус изменился с New на Closed

Экспортировать в Atom PDF

Спасибо!