63 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
function setPromt {
 | 
						|
	if [ "$color_prompt" != yes ]; then
 | 
						|
		PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
 | 
						|
		return
 | 
						|
	fi
 | 
						|
	case "$TERM" in
 | 
						|
	xterm*|rxvt*)
 | 
						|
		;;
 | 
						|
	*)
 | 
						|
		PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
 | 
						|
		return
 | 
						|
		;;
 | 
						|
	esac
 | 
						|
	PROMPT_COMMAND=updatePromt
 | 
						|
	PS2="|"
 | 
						|
}
 | 
						|
function updatePromt {
 | 
						|
	local prev_exit="$?"
 | 
						|
	# history -n; history -w; history -c; history -r;
 | 
						|
	# color_helper_>>color<< (Note: \[\]= escaping)
 | 
						|
	local chR="\[\e[1;91m\]"	  #red
 | 
						|
	local chW="\[\033[00m\]"	  #white
 | 
						|
	local chG="\[\033[01;32m\]"   #green
 | 
						|
	local chB="\[\033[0;34m\]"	  #blue
 | 
						|
	local chP="\[\033[0;35m\]"	  #purple
 | 
						|
	local chY="\[\033[0;33m\]"	  #yellow
 | 
						|
	PS1=""
 | 
						|
	if [ $prev_exit == 0 ]; then
 | 
						|
		PS1+="$chG✓ $chW"
 | 
						|
	else
 | 
						|
		PS1+="$chR✗ $chW"
 | 
						|
	fi
 | 
						|
	local jobs="$(jobs | wc -l)"
 | 
						|
	if [ $jobs != 0 ]; then
 | 
						|
		PS1+="${chY}≡$jobs$chW"
 | 
						|
	fi
 | 
						|
	PS1+="${debian_chroot:+($debian_chroot)}"
 | 
						|
	PS1+=" At ${chG}\A${chW}"
 | 
						|
	PS1+=" by ${chP}\u${chW}"
 | 
						|
	if sudo -n true 2>/dev/null; then
 | 
						|
		PS1+="${chR} (sudo)${chW}"
 | 
						|
	fi
 | 
						|
	PS1+=" in "
 | 
						|
	if \git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
 | 
						|
		local branch="$(\git symbolic-ref -q HEAD)"
 | 
						|
		PS1+="[${branch#refs/heads/}"
 | 
						|
		local status="$(git for-each-ref --format='%(upstream:trackshort)' refs/heads | awk '!seen[$1]++ {printf $1}')"
 | 
						|
		status+="$(git status --porcelain | awk '!seen[$1]++ {printf $1}')"
 | 
						|
		if [ "$statua"s ]; then
 | 
						|
			PS1+="|$chY$status$chW"
 | 
						|
		fi
 | 
						|
		PS1+="] "
 | 
						|
	fi
 | 
						|
	PS1+="${chB}\w${chW}"
 | 
						|
	PS1+="\n:"
 | 
						|
	history -a
 | 
						|
}
 | 
						|
setPromt
 | 
						|
unset color_prompt
 | 
						|
unset -f setPromt
 | 
						|
 | 
						|
# vim: set filetype=sh tabstop=4 shiftwidth=4 textwidth=250 expandtab :
 |