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

index ed023922e413828c9f9b84e508ad01caf5a7ac78..ae808a04d913bcfbf82458ccbc0d41e841a5beb4 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
@@ -246,7 +258,7 @@ eval_ldap_options() {
 
 #------------------------------------------------------------------------------
 my_date() {
-    date +'%F %T.%N %:::z'
+    date --rfc-3339=seconds
 }
 
 #------------------------------------------------------------------------------
@@ -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
 }
 
 #------------------------------------------------------------------------------