function parse_git_branch {
if [ ! -d . ]; then
return '';
fi
# We pass in the magic token bash makes from \[ and \] (^A and ^B probably)
# so we can use them in our echo statement.
#Bash 3.2 does not understand our \[ syntax for prompt escaping.. so
#sadl, no colors on it... but do colors on 4.x
if [ ${BASH_VERSINFO[0]} -ge 4 ]; then
gitcolorprompt=yes
fi
if [ $gitcolorprompt-xx == 'yes-xx' ]; then
RED="$1\e[0;31m$2"
YELLOW="$1\e[33m$2"
GREEN="$1\e[32m$2"
BLUE="$1\e[34m$2"
LIGHT_RED="$1\e[31m$2"
CYAN="$1\e[36m$2"
LIGHT_CYAN="$1\e[1;36m$2"
LIGHT_GREEN="$1\e[1;32m$2"
WHITE="$1\e[1;37m$2"
LIGHT_GRAY="$1\e[0;37m$2"
COLOR_NONE="$1\e[0m$2"
fi
if git rev-parse --git-dir &> /dev/null; then
git_status="$(git status 2> /dev/null)"
branch_pattern="^#? ?On branch ([^${IFS}]*)"
detached_branch_pattern="Not currently on any branch"
remote_pattern="Your branch is (.*) of"
diverge_pattern="Your branch and (.*) have diverged"
changed_pattern="Changes not staged for commit"
untracked_pattern="Untracked files:"
staged_pattern="Changes to be committed"
if [[ ${git_status} =~ "Changed but not updated" ]]; then
#state="${RED}⚡"
state="⚡"
fi
if [[ ${git_status} =~ ${changed_pattern} ]]; then
state="${state}Ⓜ "
fi
if [[ ${git_status} =~ ${untracked_pattern} ]]; then
state="${state}Ⓤ "
fi
if [[ ${git_status} =~ ${staged_pattern} ]]; then
#state="${state}Ⓢ "
state="${state}✇"
fi
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
#remote="${YELLOW}↑"
remote="↑"
else
#remote="${YELLOW}↓"
remote="↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
#remote="${YELLOW}↕"
remote="↕"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
elif [[ ${git_status} =~ ${detached_branch_pattern} ]]; then
branch="NO BRANCH"
#branch="${YELLOW}NO BRANCH"
fi
if [[ ${#state} -gt "0" || ${#remote} -gt "0" ]]; then
s=" "
fi
echo -e "${CYAN}[${LIGHT_GRAY}${branch}${s}${remote}${state}${changed}${CYAN}] "
#echo -e "[${branch}${s}${remote}${state}] "
fi
PROMPT_RECURSE=0
}
if [ "$PS1" ]; then
if [ $UID -eq "0" ]; then
case "$TERM" in
xterm*|rxvt*|screen)
PS1='\n\[\e]2;\u@\h:\w\a\e[1m\e[31m\]\[\e[31m\]\u\[\e[37m\]@\[\e[35m\]\h\[\e[37m\]:\[\e[32m\]\w\[\e[33m\]\[\e[31m\] #\[\e[0m\] '
;;
*)
PS1='[\!]\u@\h \w# '
;;
esac
else
case "$TERM" in
xterm*|rxvt*|screen)
#strings like \342\224\224 define UTF multi-byte chars. but we also have to wrap all but one piece
# of multi-byte chars in \[ non-printing \] or line-wrapping messes up.
#PS1='\n[\!]\[\e]2;\u@\h:\w\a\e[1m\e[33m\]\[\e[36m\]\u\[\e[37m\]@\[\e[35m\]\h\[\e[37m\]:\[\e[32m\]\w\[\e[33m\]\[\e[33m\]>\[\e[0m\] \[\e[37m\]$(parse_git_branch "\[" "\]" 2>/dev/null)\[\e[0m\]'
sadness='$([[ $? != 0 ]] && echo "[\[\033[0;31m\]\[\342\234\]\227\[\033[0;37m\]]")'
tube1="\[\342\224\]\214\[\342\224\]\200"
tube2="\[\e[37m\]\[\342\224\]\224\[\342\224\]\200\[\342\224\]\200\[\342\225\]\274"
settitle="\[\e]2;\u@\h:\w\a\e[1m\e[37m\]"
PS1="$settitle\n$tube1\[\033[0;37m\]$sadness[\[\e[0;33m\]\u\[\e[37m\]@\[\e[36m\]\h\[\e[37m\]][\[\e[0;32m\]\[\e[32m\]\w\[\e[33m\]\[\e[0;37m\]]\[\e[0m\] \[\e[37m\]\$(parse_git_branch \"\[\" \"\]\" 2>/dev/null)\n$tube2 \[\e[0m\]"
;;
*)
PS1='[\!]\u@\h \w> '
;;
esac
fi
fi
export PS1