Skip to content

Instantly share code, notes, and snippets.

@ymek
Created June 13, 2013 21:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ymek/5777370 to your computer and use it in GitHub Desktop.
Save ymek/5777370 to your computer and use it in GitHub Desktop.
autoload -U colors && colors
# between the local and remote branches
function git_remote_status() {
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
if [[ -n ${remote} ]] ; then
ahead=$(git rev-list $remote..HEAD 2>/dev/null | wc -l)
behind=$(git rev-list HEAD..$remote 2>/dev/null | wc -l)
if [ $ahead -eq 0 ] && [ $behind -eq 0 ]
then
status_str='='
else
status_str=''
if [ $ahead -gt 0 ]
then
status_str="$status_str$fg[green]+${ahead// /}$fg[yellow]"
fi
if [ $ahead -gt 0 ] && [ $behind -gt 0 ]
then
status_str="$status_str/"
fi
if [ $behind -gt 0 ]
then
status_str="$status_str$fg[red]-${behind// /}$fg[yellow]"
fi
fi
echo $status_str
fi
}
function git_remote_prompt() {
prompt_info=$(git_prompt_info) || return
echo " %{$fg[yellow]%}[$prompt_info$(git_remote_status)]%{$reset_color%}"
}
PROMPT='%{$fg_bold[green]%}%n@%m %{$fg_bold[blue]%}%(!.%1~.%~)%{$reset_color%}$(git_remote_prompt)$(git_prompt_short_sha) %(!.#.») '
ZSH_THEME_GIT_PROMPT_PREFIX=""
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_SHA_BEFORE="%{$fg[red]%}["
ZSH_THEME_GIT_PROMPT_SHA_AFTER="]%{$reset_color%}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment