app-shells/bash: bashrc: drop custom parsing of dircolors databases #572582
authorMike Frysinger <vapier@gentoo.org>
Tue, 2 Feb 2016 22:08:19 +0000 (17:08 -0500)
committerMike Frysinger <vapier@gentoo.org>
Wed, 3 Feb 2016 18:51:41 +0000 (13:51 -0500)
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>
app-shells/bash/files/bashrc

index c5b449bf837a2300f42109c78b60649cd6751d5b..414f8482569c4c3ee11266b4d78580fb748ab29d 100644 (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