From 78c78dd6fe1f3e479c16592ebf092186f6b2b2b1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 3 Sep 2016 00:32:32 +1200 Subject: Test number of colors properly for prompt --- bash/bashrc.d/prompt.bash | 57 +++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) (limited to 'bash/bashrc.d') diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 55c33282..3b99cc12 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -45,37 +45,32 @@ prompt() { # Decide prompt color formatting based on color availability local format - case $colors in - - # Check if we have non-bold bright green available - 256) - format=$( { - : "${PROMPT_COLOR:=10}" - tput setaf "$PROMPT_COLOR" || - tput setaf "$PROMPT_COLOR" 0 0 || - tput AF "$PROMPT_COLOR" || - tput AF "$PROMPT_COLOR" 0 0 - } 2>/dev/null ) - ;; - - # If we have only eight colors, use bold green - 8) - format=$( { - : "${PROMPT_COLOR:=2}" - tput setaf "$PROMPT_COLOR" || - tput AF "$PROMPT_COLOR" - tput bold || tput md - } 2>/dev/null ) - ;; - - # For all other terminals, we assume non-color (!), and we just - # use bold - *) - format=$( { - tput bold || tput md - } 2>/dev/null ) - ;; - esac + + # Check if we have non-bold bright green available + if ((colors >= 16)) ; then + format=$( { + : "${PROMPT_COLOR:=10}" + tput setaf "$PROMPT_COLOR" || + tput setaf "$PROMPT_COLOR" 0 0 || + tput AF "$PROMPT_COLOR" || + tput AF "$PROMPT_COLOR" 0 0 + } 2>/dev/null ) + + # If we have only eight colors, use bold green + elif ((colors >= 8)) ; then + format=$( { + : "${PROMPT_COLOR:=2}" + tput setaf "$PROMPT_COLOR" || + tput AF "$PROMPT_COLOR" + tput bold || tput md + } 2>/dev/null ) + + # Otherwise, we just try bold + else + format=$( { + tput bold || tput md + } 2>/dev/null ) + fi # String it all together PS1='\['"$format"'\]'"$PS1"'\['"$reset"'\] ' -- cgit v1.2.3