43 lines
		
	
	
	
		
			899 B
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
	
		
			899 B
		
	
	
	
		
			Bash
		
	
	
	
	
	
| prompt_color_fail=(204 0 0)
 | |
| prompt_color_pass=(102 255 153)
 | |
| 
 | |
| if hash git 2>/dev/null; then
 | |
|   prompt_has_git=true
 | |
| fi
 | |
| 
 | |
| prompt_color_reset=$(tput sgr0)
 | |
| 
 | |
| symbol-decorate() {
 | |
|   local -n prompt_colors=$1
 | |
|   local r=${prompt_colors[0]} g=${prompt_colors[1]} b=${prompt_colors[2]}
 | |
|   printf '\[\e[38;2;%d;%d;%dm\]%s\[%s\]' "$r" "$g" "$b" "$prompt_symbol" "$(tput sgr0)"
 | |
| }
 | |
| 
 | |
| prompt-decorate() {
 | |
|   local res=$? prompt_str
 | |
| 
 | |
|   # prepend the 
 | |
|   if [[ -v SSH_CLIENT && -v HOSTNAME ]]; then
 | |
|     prompt_str+=$HOSTNAME:
 | |
|   fi
 | |
| 
 | |
|   prompt_str+="\w "
 | |
| 
 | |
|   if [[ -v prompt_has_git && -d .git ]]; then
 | |
|     prompt_str+="$(command git branch --show-current) "
 | |
|   fi
 | |
| 
 | |
|   if [[ ! -v prompt_symbol ]]; then
 | |
|     prompt_symbol='\$'
 | |
|   fi
 | |
| 
 | |
|   if (( res )); then
 | |
|     prompt_str+=$(symbol-decorate prompt_color_fail)
 | |
|   else
 | |
|     prompt_str+=$(symbol-decorate  prompt_color_pass)
 | |
|   fi
 | |
| 
 | |
|   PS1="$prompt_str "
 | |
| }
 | |
| 
 | |
| PROMPT_COMMAND+=(prompt-decorate)
 |