Hi! I'm Nathan Hoad


Git: Bash tab completions and a cool prompt

Git is pretty awesome to begin with but you can easily make it more awesome by adding two things: Tab completions in Terminal and a sweet (and useful) Bash prompt.

Open up ~/.bash_profile in your favourite editor and paste this in somewhere. You might need to change the location of Git - this one is from my Snow Leopard standard install.

source /usr/local/git/contrib/completion/git-completion.bash

Next up (and still in the same file), add this somewhere:

function parse_git_dirty {
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}

export PS1='\n\[\e[36;1m\]\w\[\e[0m\] $(__git_ps1 "[\[\e[0;32m\]%s\[\e[0m\]\[\e[0;33m\]$(parse_git_dirty)\[\e[0m\]]")\n\$ \[\e[0m\]'

This will replace your standard Bash prompt with a sweet Git-enabled one. When you are in a directory controlled by Git you will be shown he current branch and if there are any changes. I've picked colours that work for me but with a little bit of work you can customise things to your own liking. For more information on how to do that checkout this guide on Cusomtizing Your Bash Prompt.

If I just made your day a little better then thank me with a coffee or maybe a a pizza