From d706267b4a181a8e18c4a83f88f23b77a5345882 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 14 Aug 2019 14:48:53 +0200 Subject: [PATCH] Changing detecting color --- lib/functions.rc | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/functions.rc b/lib/functions.rc index ed02392..ae808a0 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -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}$(/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 } #------------------------------------------------------------------------------ -- 2.39.5