Skip to content

Instantly share code, notes, and snippets.

@amikula
Forked from halbtuerke/gist:31934
Created May 15, 2009 23:36
Show Gist options
  • Save amikula/112494 to your computer and use it in GitHub Desktop.
Save amikula/112494 to your computer and use it in GitHub Desktop.
Zsh translation
autoload -U colors
colors
setopt prompt_subst
parse_git_branch() {
local state remote
git rev-parse --git-dir &> /dev/null
git_status="$(git status 2> /dev/null)"
branch_pattern="# On branch ([[:alnum:]/]*)"
remote_pattern="# Your branch is (.*) of"
diverge_pattern="# Your branch and (.*) have diverged"
if [[ ! ${git_status} =~ "working directory clean" ]]; then
state="%{$fg[red]%}⚡"
fi
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${match[1]} == "ahead" ]]; then
remote="%{$fg[yellow]%}↑"
else
remote="%{$fg[yellow]%}↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="%{$fg[yellow]%}↕"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${match[1]}
echo " (${branch})${remote}${state}"
fi
}
PROMPT='${TITLEBAR}%{$fg[blue]%}[%{$fg[red]%}%~%{$fg[green]%}$(parse_git_branch)%{$fg[blue]%}] %(?.%{$reset_color%}.%{$fg[red]%})➔%{$reset_color%} '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment