From 9633ac83cad5f5702c1e853940c0ab2e166961bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 1 Jul 2014 00:32:46 +0200 Subject: [PATCH] hostname: fix LP_ENABLE_SSH_COLORS Colorization of the hostname based on a hash of the name was broken for some time because t_setaf was not available where LP_COLOR_SSH was used. --- liquidprompt | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/liquidprompt b/liquidprompt index b4cd8b6..2ec222d 100755 --- a/liquidprompt +++ b/liquidprompt @@ -248,6 +248,12 @@ _lp_source_config() # NO_COL is special: it will be used at runtime, not just during config loading NO_COL="${_LP_OPEN_ESC}${ti_sgr0}${_LP_CLOSE_ESC}" + # compute the hash of the hostname + # and get the corresponding number in [1-6] (red,green,yellow,blue,purple or cyan) + # FIXME check portability of cksum and add more formats (bold? 256 colors?) + local hash=$(( 1 + $(hostname | cksum | cut -d " " -f 1) % 6 )) + LP_COLOR_HOST_HASH="${_LP_OPEN_ESC}$(ti_setaf $hash)${_LP_CLOSE_ESC}" + unset ti_sgr0 ti_bold ti_setaf ti_setab @@ -525,19 +531,8 @@ lcl) ;; ssh) # If we want a different color for each host - if [[ "$LP_ENABLE_SSH_COLORS" -eq "1" ]]; then - # compute the hash of the hostname - # and get the corresponding number in [1-6] (red,green,yellow,blue,purple or cyan) - # FIXME check portability of cksum and add more formats (bold? 256 colors?) - hash=$(( 1 + $(hostname | cksum | cut -d " " -f 1) % 6 )) - color=${_LP_OPEN_ESC}$(ti_setaf $hash)${_LP_CLOSE_ESC} - LP_HOST="${LP_HOST}${color}${_LP_HOST_SYMBOL}${NO_COL}" - unset hash - unset color - else - # the same color for all hosts - LP_HOST="${LP_HOST}${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}" - fi + [[ "$LP_ENABLE_SSH_COLORS" -eq 1 ]] && LP_COLOR_SSH="$LP_COLOR_HOST_HASH" + LP_HOST="${LP_HOST}${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}" ;; su) LP_HOST="${LP_HOST}${LP_COLOR_SU}${_LP_HOST_SYMBOL}${NO_COL}"