Skip to content

Instantly share code, notes, and snippets.

@theory
Created April 27, 2009 02:25
Show Gist options
  • Save theory/102291 to your computer and use it in GitHub Desktop.
Save theory/102291 to your computer and use it in GitHub Desktop.
# Git function from http://github.com/bkerley/zshkit/raw/master/06_git.
autoload -Uz colors
colors
if [[ -x `which git` ]]; then
function git-prompt() {
gstatus=$(git status 2> /dev/null)
branch=$(echo $gstatus | head -1 | sed 's/^# On branch //')
dirty=$(echo $gstatus | sed 's/^#.*$//' | tail -2 | grep 'nothing to commit (working directory clean)'; echo $?)
if [[ x$branch != x ]]; then
dirty_color=$fg[cyan]
if [[ $dirty = 1 ]] { dirty_color=$fg[magenta] }
[ x$branch != x ] && echo " %{$dirty_color%}$branch%{$reset_color%} "
fi
}
else
function git-prompt() {
echo ''
}
fi
setopt prompt_subst
PROMPT='%{$reset_color%}%m %~`git-prompt`%(!.#.>) '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment