From: Frank Brehm Date: Wed, 14 Aug 2019 10:01:10 +0000 (+0200) Subject: Changing detecting colors X-Git-Tag: 0.4.1~10^2~2 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=ae71d1fa09525f461a19987162f468990095be4d;p=pixelpark%2Fpp-admin-tools.git Changing detecting colors --- diff --git a/lib/functions.rc b/lib/functions.rc index ed02392..5f05290 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 @@ -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 } #------------------------------------------------------------------------------