aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/prompt.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-08-05 00:32:53 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-08-05 00:32:53 +1200
commitfd760f78eda9273941179024ad2588b9191f4735 (patch)
tree896710a417dd4bce65839deb88e38cd4e2bb357e /bash/bashrc.d/prompt.bash
parentAdd sprunge script for my convenience (diff)
downloaddotfiles-fd760f78eda9273941179024ad2588b9191f4735.tar.gz
dotfiles-fd760f78eda9273941179024ad2588b9191f4735.zip
Improve color detection logic for prompt/ls/grep
Use tput properly and only when found and necessary
Diffstat (limited to 'bash/bashrc.d/prompt.bash')
-rw-r--r--bash/bashrc.d/prompt.bash36
1 files changed, 24 insertions, 12 deletions
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