app-shells/bash: bashrc: drop custom parsing of dircolors databases #572582

Starting with coreutils-8.24, the dircolors TERM entries are run through
fnmatch rather than being a plain text string.  This means our parsing
logic no longer works because we assumed fixed strings.  It isn't easy to
process a list of path globs in bash, so rework the code to always run
the dircolors tool.  We were doing this anyways in the majority of cases,
so it's not like we're adding that much overhead.  The only people who
are negatively impacted are interactive colorless terminals.

Reported-by: Bernd Feige <Bernd.Feige@gmx.net>
This commit is contained in:
Mike Frysinger
2016-02-02 17:08:19 -05:00
parent 485b78806b
commit 7478574083

View File

@@ -52,27 +52,19 @@ esac
# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions. Use internal bash
# globbing instead of external grep binary.
# first to take advantage of user additions.
use_color=false
safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
match_lhs=""
[[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs} ]] \
&& type -P dircolors >/dev/null \
&& match_lhs=$(dircolors --print-database)
[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
if ${use_color} ; then
if type -P dircolors >/dev/null ; then
# Enable colors for ls, etc. Prefer ~/.dir_colors #64489
if type -P dircolors >/dev/null ; then
if [[ -f ~/.dir_colors ]] ; then
eval "$(dircolors -b ~/.dir_colors)"
elif [[ -f /etc/DIR_COLORS ]] ; then
eval "$(dircolors -b /etc/DIR_COLORS)"
fi
LS_COLORS=
if [[ -f ~/.dir_colors ]] ; then
eval "$(dircolors -b ~/.dir_colors)"
elif [[ -f /etc/DIR_COLORS ]] ; then
eval "$(dircolors -b /etc/DIR_COLORS)"
else
eval "$(dircolors -b)"
fi
[[ -n ${LS_COLORS:+set} ]] && use_color=true
else
# Some systems (e.g. BSD & embedded) don't typically come with
# dircolors so we need to hardcode some terminals in here.
@@ -107,4 +99,4 @@ for sh in /etc/bash/bashrc.d/* ; do
done
# Try to keep environment pollution down, EPA loves us.
unset use_color safe_term match_lhs sh
unset use_color sh