From 8f6f397538c1b346607ab88d6499d24765efebd7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 25 Mar 2015 19:23:00 +1300 Subject: Change if-elseif chain to a switch-case --- bash/bashrc.d/prompt.bash | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'bash/bashrc.d') diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 9aae086d..128717d8 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -30,26 +30,33 @@ prompt() { } 2>/dev/null ) local format - # Check if we have non-bold bright green available - if ((colors == 256)) ; then - format=$( { - tput AF 10 || tput setaf 10 \ - || tput AF 10 0 0 || tput setaf 10 0 0 - } 2>/dev/null ) - - # If we have only eight colors, use bold green to make it bright - elif ((colors == 8)) ; then - format=$( { - tput AF 2 || tput setaf 2 - tput md || tput bold - } 2>/dev/null ) - - # For non-color terminals (!), just use bold - else - format=$( { - tput md || tput bold - } 2>/dev/null ) - fi + # Decide prompt color formatting based on color availability + case $colors in + + # Check if we have non-bold bright green available + 256) + format=$( { + tput AF 10 || tput setaf 10 \ + || tput AF 10 0 0 || tput setaf 10 0 0 + } 2>/dev/null ) + ;; + + # If we have only eight colors, use bold green + 8) + format=$( { + tput AF 2 || tput setaf 2 + tput md || tput bold + } 2>/dev/null ) + ;; + + # For all other terminals, we assume non-color (!), and we just + # use bold + *) + format=$( { + tput md || tput bold + } 2>/dev/null ) + ;; + esac # String it all together PS1='\['"$format"'\]'"$PS1"'\['"$reset"'\] ' -- cgit v1.2.3