Skip to content

Instantly share code, notes, and snippets.

@chrislawlor
Last active January 3, 2016 14:09
Show Gist options
  • Save chrislawlor/8474185 to your computer and use it in GitHub Desktop.
Save chrislawlor/8474185 to your computer and use it in GitHub Desktop.
Bash prompt - add Git branch and 'dirty' status, e.g. user@localhost:~/code/project on develop⚡ Add to your ~/.bashrc (linux) or ~/.bash_profile (OSX)
# Custom prompt
function parse_git_dirty {
git branch > /dev/null 2>&1
if [[ $(echo $?) == "0" ]]
then [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "⚡"
fi
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/on \1/"
}
export PS1='\e[0;32m\u@localhost:\w \e[0;35m$(parse_git_branch)\e[0;33m$(parse_git_dirty)\e[m\n$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment