# PS1 Prompt: The prompt should show the git branch and whether the local branch has been
# modified.
PS1_git_color() {
    # These two do not have the escape (\[) character since those are
    # only special when shown *within* PS1.  The escape chars are in
    # the PS1 def below.
    local BRANCH_MOD="$(tput bold)$(tput setf 6)$(tput setb 4)"
    local BRANCH_UNMOD="$(tput bold)$(tput setf 2)"
    if [ -z "$(git status -s 2> /dev/null)" ] ; then
        echo "${BRANCH_UNMOD}"
    else
        echo "${BRANCH_MOD}"
    fi
}

PS1_git_branch() {
    local BRANCH_WIDTH=$(( ${COLUMNS}/4 ))
    local branch="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
    echo ${branch:0:${BRANCH_WIDTH}}
}

BOLDWHITE="\[$(tput bold)$(tput setf 7)\]"
NOCOLOR="\[$(tput sgr0)\]"

export PS1="\u@\h ${BOLDWHITE}\W \[\$(PS1_git_color)\]\$(PS1_git_branch)${NOCOLOR} $ "
unset BOLDWHITE
unset NOCOLOR
