Skip to content

Instantly share code, notes, and snippets.

@hchbaw
Created May 19, 2010 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hchbaw/406328 to your computer and use it in GitHub Desktop.
Save hchbaw/406328 to your computer and use it in GitHub Desktop.
#!zsh
# _git vcs_info
# __git_branch_switches
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
#zstyle ':vcs_info:*' formats '%B%F{black}(%f%b%F{black})%f%%b' # `%f` eats "1"
zstyle ':vcs_info:*' formats '%B%F{black}(%F{white}%b%F{black})%f%%b'
zstyle ':vcs_info:*' actionformats '%B%F{black}(%F{white}%b%F{black}|%F{white}%a%F{black})%f%%b'
__git_revisions_fu () {
__git_branch_switches
__git_revisions
}
__git_branch_switches () {
local expl gitdir
typeset -a branch_switches
gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
__git_command_successful || return
[[ -f ${gitdir}/logs/HEAD ]] || return
local sha1ish='????????????????????????????????????????'
branch_switches=(${(Oau)${${${${(M)${(@f)"$(<${gitdir}/logs/HEAD)"}:#*checkout: moving from *}#*checkout: moving from }%% to *}:#${~sha1ish}}})
local b=$(_call_program gitsymbolicref git symbolic-ref HEAD 2>/dev/null)
__git_command_successful || return
: ${(A)branch_switches::=${branch_switches:#${b##refs/heads/}}}
_wanted -V branch-switches expl branch-switch compadd $* - $branch_switches
}
my__git_func_body () {
local fname="$1"
local place="$2"
: ${(P)place::=${${functions[_git]##*${fname} \(\)}%%\(\( \$+functions*}}
}
my__git_initialize () {
local vcs_info_fu_p=$1
autoload +X _git
[[ -z $vcs_info_fu_p ]] || eval "function _git { ${functions[_git]/\{/{
{ vcs_info; local expl; _message \$vcs_info_msg_0_ \}}
}
#}}"
local code=''
my__git_func_body git-checkout code
eval "function _git-checkout () ${code//:__git_revisions/:__git_revisions_fu}"
zstyle ':completion::complete:git:*' group-order branch-switches
}
my__git_initialize t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment