Skip to content

Instantly share code, notes, and snippets.

@mrnejc
Created April 23, 2014 14:00
Show Gist options
  • Save mrnejc/11216267 to your computer and use it in GitHub Desktop.
Save mrnejc/11216267 to your computer and use it in GitHub Desktop.
bash prompt - colourful git status
# got it via http://aussie.lunix.com.au/blog/2013/02/08/coloured-git-status-in-your-bash-prompt/
# put into .bashrc or .bash_profile
function _git_prompt() {
local git_status="`git status -unormal 2>&1`"
if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
if [[ "$git_status" =~ nothing\ to\ commit ]]; then
local ansi=32
elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
local ansi=34
else
local ansi=33
fi
echo -n '\[\e[0;33;'"$ansi"'m\]'"$(__git_ps1)"'\[\e[0m\]'
fi
}
function _prompt_command() {
PS1="[\[\033[32m\]\w\[\033[0m\]]\[\033[0m\]\n\[\033[1;36m\]\u@\[\033[0;37m\]\h] `_git_prompt` \[\033[1;33m\]-> \[\033[0m\]"
}
PROMPT_COMMAND=_prompt_command
# if you get
# -bash: __git_ps1: command not found
# error do
# $ curl https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
# and add
# source ~/.bash_git
# above this code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment