commit:     747857408315deb4b6a0ddd2a34484ca8e5ec2ff
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Tue Feb  2 22:08:19 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Feb  3 18:51:41 2016 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=74785740

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 <AT> gmx.net>

 app-shells/bash/files/bashrc | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/app-shells/bash/files/bashrc b/app-shells/bash/files/bashrc
index c5b449b..414f848 100644
--- a/app-shells/bash/files/bashrc
+++ b/app-shells/bash/files/bashrc
@@ -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

Reply via email to