]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Changing detecting colors
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 14 Aug 2019 10:01:10 +0000 (12:01 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 14 Aug 2019 10:01:10 +0000 (12:01 +0200)
lib/functions.rc

index ed023922e413828c9f9b84e508ad01caf5a7ac78..5f05290613ed4eea78cf0239d44c9af7be15155c 100644 (file)
@@ -69,12 +69,24 @@ detect_color() {
     local safe_term="${TERM//[^[:alnum:]]/?}"
     local match_lhs=""
     local use_color="false"
-    [[ -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"
+    local term=
+
+    if [[ -f ~/.dir_colors   ]] ; then
+        match_lhs="${match_lhs}$( cat ~/.dir_colors | grep '^TERM ' | sed -e 's/^TERM  *//' -e 's/ .*//')"
+    fi
+    if [[ -f /etc/DIR_COLORS   ]] ; then
+        match_lhs="${match_lhs}$( cat /etc/DIR_COLORS | grep '^TERM ' | sed -e 's/^TERM  *//' -e 's/ .*//')"
+    fi
+    if [[ -z ${match_lhs} ]] ; then
+        type -P dircolors >/dev/null && \
+        match_lhs=$(dircolors --print-database | grep '^TERM ' | sed -e 's/^TERM  *//' -e 's/ .*//')
+    fi
+    for term in ${match_lhs} ; do
+        if [[ "${safe_term}" == ${term} || "${TERM}" == ${term} ]] ; then
+            use_color="true"
+            break
+        fi
+    done
 
     # console colors:
     if [ "${use_color}" = "true" ] ; then
@@ -254,7 +266,7 @@ debug() {
     if [[ "${VERBOSE}" != "y" ]] ; then
         return 0
     fi
-    echo -e " * [$(my_date)] [${BASE_NAME}:DEBUG]: $@" >&2
+    echo -e " * [$(my_date)] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $@" >&2
 }
 
 #------------------------------------------------------------------------------