Skip to content

Instantly share code, notes, and snippets.

@pedroburon
Forked from pvalencia/.bashrc
Created March 11, 2013 13:40
Show Gist options
  • Save pedroburon/5134303 to your computer and use it in GitHub Desktop.
Save pedroburon/5134303 to your computer and use it in GitHub Desktop.
function get_short_commit {
git log -n 1 --format=oneline --abbrev-commit 2> /dev/null | sed -e 's/\([0-9a-f]*\)\(.*\)/\1/'
}
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 $(get_short_commit)]$(parse_git_dirty)/"
}
if [ "\$(type -t __git_ps1)" ]; then
PS1="\$(parse_git_branch)\n$PS1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment