Sunday, February 3, 2013

Custom BASH Prompt (PS1) + Git Support

/etc/profile

if [ -f "/usr/local/git/current/share/git-core/git-completion.bash" ] ; then
  source "/usr/local/git/current/share/git-core/git-completion.bash"
  source "/usr/local/git/current/share/git-core/git-prompt.sh"
fi

export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1

if ! hash __git_ps1 2>/dev/null
then
__git_ps1 () { echo -n -e '!'; }    
fi

if [[ "$SHELL" = *bash* ]] && ( [[ "$TERM" = *xterm* ]] || [[ "$TERM" = *vt100* ]] )
then
        USER_ID=`id | cut -d"(" -f2 | cut -f1 -d ")"`
        if [ "$USER_ID" = "root" ]
        then
               PS1="\[\e[1;31m\][\t] \u@\h \[\e[01;34m\]\W \`__git_ps1 "[%s]"\`\`if [ \$? = 0 ]; then echo -e '\[\e[01;32m\]:)'; else echo -n -e '\[\e[01;31m\]:( $EXIT_STATUS'; fi\` \\$\[\e[0m\]\n"
        else
                PS1="\[\e[01;32m\][\t] \u@\[\e[97m\]\h \[\e[01;34m\]\W \`__git_ps1 "[%s]"\`\`if [ \$? = 0 ]; then echo -e '\[\e[01;32m\]:)'; else echo -n -e '\[\e[01;31m\]:( $EXIT_STATUS'; fi\` \[\e[01;34m\]$\[\e[00m\]\n"
        fi
fi

No comments: