diff options
-rw-r--r-- | bash/bashrc.d/grep.bash | 2 | ||||
-rw-r--r-- | bash/bashrc.d/ls.bash | 2 | ||||
-rw-r--r-- | bash/bashrc.d/prompt.bash | 36 |
3 files changed, 26 insertions, 14 deletions
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash index 62acdb01..37061916 100644 --- a/bash/bashrc.d/grep.bash +++ b/bash/bashrc.d/grep.bash @@ -2,7 +2,7 @@ __grepopts() { local grepopts='-I' local grephelp="$(grep --help 2>/dev/null)" - if [[ "$grephelp" == *--color* ]]; then + if [[ "$grephelp" == *--color* && "$(tput colors)" -ge 8 ]]; then grepopts="${grepopts} --color=auto" fi if [[ "$grephelp" == *--exclude* ]]; then diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash index d1afd04c..0fda4ed8 100644 --- a/bash/bashrc.d/ls.bash +++ b/bash/bashrc.d/ls.bash @@ -2,7 +2,7 @@ __lsopts() { local lsopts= local lshelp="$(ls --help 2>/dev/null)" - if [[ "$lshelp" == *--color* ]]; then + if [[ "$lshelp" == *--color* && "$(tput colors)" -ge 8 ]]; then lsopts="${lsopts} --color=auto" fi printf '%s' "$lsopts" diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index a648fe94..2b675dad 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -3,26 +3,38 @@ prompt() { # Variables for use only within this function local -i ret=$? - local -i colors=$(tput colors 2>/dev/null) local color reset branch state info url root - # Figure out how many colors we have to work with - if [[ $colors -ge 256 ]]; then - color='\[\e[38;5;10m\]' - reset='\[\e[0m\]' - elif [[ $colors -ge 8 ]]; then - color='\[\e[1;32m\]' - reset='\[\e[0m\]' - fi - # What's done next depends on the first argument to the function case "$1" in - # Turn complex coloured prompt on + # Turn complex, colored prompt on on) PROMPT_COMMAND='history -a' PS1='\[\a\][\u@\h:\w]$(prompt return)$(prompt vcs)$(prompt jobs)\$' - PS1="${color}${PS1}${reset} " + + # If we have tput available, get some color codes + if command -v tput &>/dev/null; then + + # Check if we have non-bold bright green available + if [[ "$(tput colors)" -gt 8 ]]; then + color="$(tput setaf 10)" + + # If we don't, fall back to the bold green + else + color="$(tput setaf 2)$(tput bold)" + fi + + # Reset color and attributes + reset="$(tput sgr0)" + + # String it all together + PS1="\\[$color\\]$PS1\\[$reset\\] " + + # No colors, just add a space + else + PS1="$PS1 " + fi ;; # Revert to simple inexpensive prompt |