Skip to content

Instantly share code, notes, and snippets.

@indirect
Created October 18, 2010 02:49
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indirect/631628 to your computer and use it in GitHub Desktop.
Save indirect/631628 to your computer and use it in GitHub Desktop.
improved git prompt yay
# [andre ~/.bash](master)$ # clean working directory
# [andre ~/.bash](master⚡)$ # dirty working directory
# [andre ~/.bash](master~2)$ # checked out revision not a branch
# [andre ~/.bash](branch)$ # checked out branch with same commits as master
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
}
function parse_git_branch {
local b="$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/^* //')"
if [ -n "$b" ] && [ "$b" = "(no branch)" ]; then
local b="$(git name-rev --name-only HEAD 2> /dev/null)"
fi
if [ -n "$b" ]; then
printf "($b$(parse_git_dirty))"
fi
}
export PS1='\[\033k\033\\\]\[\e[0;34m\][\u \w]$(parse_git_branch)\$\[\e[0;39m\] '
@indirect
Copy link
Author

The main reason I wrote my own is that __git_ps1 doesn't support non-branch locations, like master~2. If that's changed, I'm a happy man. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment