There’s a pretty nifty function within the git bash-completion script, and since i only want to show the current git branch to know where i am currently at, copying that one, integrating it with the existing fast optical user identification code in .bashrc.

$ vim ~/.bashrc
# =========================================================
# COLOR PROMPTS WITH GIT BRANCH
# =========================================================
function formattedGitBranch {
        _branch="$(git branch 2>/dev/null | sed -e "/^s/d" -e "s/^*s//")"
        test -n "$_branch" && echo -e " @e[0;32m $_branch"
}

if [ `/usr/bin/whoami` = 'root' ]
then
export XFOUND_ROOT_USER='YES'
        # Do not set PS1 for dumb terminals
        if [ "$TERM" != 'dumb'  ] && [ -n "$BASH" ]
        then
                export PS1='[33[01;31m]h[e[m] [e[1;34m]w[e[m]$(formattedGitBranch) [e[1;34m]$ [e[m][e[0m]'
        fi
else
export XFOUND_NORMAL_USER='YES'
        # Do not set PS1 for dumb terminals
        if [ "$TERM" != 'dumb'  ] && [ -n "$BASH" ]
        then
                export PS1='[33[01;32m]u@h[e[m] [e[1;34m]w[e[m]$(formattedGitBranch) [e[1;34m]$ [e[m][e[0m]'
        fi
fi
$ . ~/.bashrc

See how it works 🙂

%d bloggers like this: