Skip to content

Instantly share code, notes, and snippets.

@pvalencia
Forked from henrik/.bashrc
Created May 20, 2010 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pvalencia/407136 to your computer and use it in GitHub Desktop.
Save pvalencia/407136 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