~/.bash_profile Contents
Run the git completion script so that commands like __git_ps1 are available:
# enable the git bash completion commands source ~/.git-completion
Turn on a couple of options for use with the __git_ps1 script. Please see the comments in .git-completion for an explanation on what each one does (I don’t want to duplicate their documentation here):
# enable git unstaged indicators - set to a non-empty value GIT_PS1_SHOWDIRTYSTATE="." # enable showing of untracked files - set to a non-empty value GIT_PS1_SHOWUNTRACKEDFILES="." # enable stash checking - set to a non-empty value GIT_PS1_SHOWSTASHSTATE="." # enable showing of HEAD vs its upstream GIT_PS1_SHOWUPSTREAM="auto"
Set some variables that will be called as shell commands later – these ones are for changing the text colour. I’m not using all these colours in this script but they’re useful to know. Note that I found these colours on a Stack Overflow question titled "How do I get my iTerm prompt to display differently when I’m in a Git branch?" – thanks SiegeX.
BLACK=$(tput setaf 0) RED=$(tput setaf 1) GREEN=$(tput setaf 2) YELLOW=$(tput setaf 3) LIME_YELLOW=$(tput setaf 190) POWDER_BLUE=$(tput setaf 153) BLUE=$(tput setaf 4) MAGENTA=$(tput setaf 5) CYAN=$(tput setaf 6) WHITE=$(tput setaf 7) BRIGHT=$(tput bold) NORMAL=$(tput sgr0) BLINK=$(tput blink) REVERSE=$(tput smso) UNDERLINE=$(tput smul)
Add a function that figures out whether or not you’re in a git branch (for showing the prompt prefix):
# return the prompt prefix for the second line function set_prefix { BRANCH=`__git_ps1` if [[ -z $BRANCH ]]; then echo "${NORMAL}o" else echo "${UNDERLINE}+" fi }
Set the prompt itself. Please remember that I’m guessing at Paul’s actual usage but this is pretty close:
# and here's one similar to Paul Irish's famous prompt ... not sure if this is the way he does it, but it works :) # 33[s = save cursor position # 33[u = restore cursor position PS1='${MAGENTA}u${WHITE} in ${GREEN}w${WHITE}${MAGENTA}`__git_ps1 " on %s"`${WHITE}rn`set_prefix`${NORMAL}${CYAN}33[s33[60C (`date "+%a, %b %d"`)33[u${WHITE} '