Skip to content

Instantly share code, notes, and snippets.

@orlin
Created January 16, 2012 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlin/1620835 to your computer and use it in GitHub Desktop.
Save orlin/1620835 to your computer and use it in GitHub Desktop.
bash git prompt
WHITE="\[\033[1;37m\]"
BLUE="\[\033[0;34m\]"
GREEN="\[\033[0;32m\]"
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
PURPLE="\[\033[0;35m\]"
function parse_git_branch {
ref=$(git-symbolic-ref HEAD 2> /dev/null) || return
echo "["${ref#refs/heads/}"]"
}
my_git_status() {
branch_prompt=$(__git_ps1)
if [ -n "$branch_prompt" ]; then
if [ `git config --bool --get bash.showdirtystate` ]; then
if current_git_status=$(git status | grep 'added to commit' 2> /dev/null); then
echo "⚠ "
fi
fi
fi
}
my_git_propmt() {
branch_prompt=$(__git_ps1)
if [ -n "$branch_prompt" ]; then
my_prompt=$(__git_ps1 "%s") # no parentheses around branchname
if current_git_status=$(git status | grep 'added to commit' 2> /dev/null); then
echo "$my_prompt "
else
echo "$my_prompt » "
fi
fi
}
my_sha() {
sha=$(git rev-parse --short HEAD 2>/dev/null) || return
echo "@$sha "
}
# non-zero exit status (of the last command) is bad.
bad_exit() {
if test $1 -ne 0 ; then
echo "▻$1◅ "
fi
}
PS1="${WHITE}⚚ $RED\$(bad_exit \$?)$WHITE\$(my_sha)$PURPLE\$(my_git_propmt)$RED\$(my_git_status)$YELLOW\w$WHITE ➔ $GREEN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment