diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-03 00:32:32 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-03 00:32:32 +1200 |
commit | 78c78dd6fe1f3e479c16592ebf092186f6b2b2b1 (patch) | |
tree | a7bfad0a20ed9fe5993f0c500f5fb75ad5e7e69b /bash/bashrc.d | |
parent | "From" and "From:" are two differnet headers (diff) | |
download | dotfiles-78c78dd6fe1f3e479c16592ebf092186f6b2b2b1.tar.gz dotfiles-78c78dd6fe1f3e479c16592ebf092186f6b2b2b1.zip |
Test number of colors properly for prompt
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r-- | bash/bashrc.d/prompt.bash | 57 |
1 files changed, 26 insertions, 31 deletions
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"'\] ' |