Skip to content

Instantly share code, notes, and snippets.

@clairvy
Forked from hchbaw/zsh.zsh
Created September 22, 2010 13:08
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 clairvy/591626 to your computer and use it in GitHub Desktop.
Save clairvy/591626 to your computer and use it in GitHub Desktop.
#!zsh
# __git_branch_switches
# _git-submodule
# _git-filter-branch
(( $+functions[_git-now] )) ||
_git-now () {
local curcontext=$curcontext state line
declare -A opt_args
_arguments -C \
'(-n --dry-run)'{-n,--dry-run}'[do not actually add files; only show which ones would be added]' \
'(-v --verbose)'{-v,--verbose}'[show files as they are added]' \
'(-f --force)'{-f,--force}'[allow adding otherwise ignored files]' \
'(-i --interactive : -)'{-i,--interactive}'[add contents interactively to the index]' \
'(-p --patch)'{-p,--patch}'[like -i but go directly into patch mode for specified files]' \
'(-u --update -A --all)'{-u,--update}'[update only files git already knows about]' \
'(-A --all -u --update)'{-A,--all}'[act as both add . and add -u]' \
'(-N --intent-to-add)'{-N,--intent-to-add}'[record only that the path will be added later]' \
'--refresh[do not add files, but refresh their stat() info in the index]' \
'--ignore-errors[continue adding if an error occurs]' \
'--rebase[rebase from oldest commit by git-now]' \
'*:file:->files' && ret=0
case $state in
(files)
declare -a ignored_files_alternatives
if (( words[(I)-f] )); then
ignored_files_alternatives=(
'ignored-modified-files:ignored modified files:__git_modified_files --ignored'
'ignored-other-files:ignored other files:__git_other_files --ignored')
fi
_alternative \
'modified-files:modified files:__git_modified_files' \
'other-files:other files:__git_other_files' \
$ignored_files_alternatives && ret=0
;;
esac
}
(( $+functions[_git-filter-branch] )) ||
_git-filter-branch () {
local curcontext=$curcontext state line
declare -A opt_args
_arguments -C \
'--env-filter[rewrite the author/committer name/email/time environment variables]:command' \
'--tree-filter[rewriting the tree and its contents]:command' \
'--index-filter[rewriting the index]:command' \
'--parent-filter[rewriting the commit'\''s parent list]:command' \
'--msg-filter[rewriting the commit messages]:command' \
'--commit-filter[performing the commit]:command' \
'--tag-name-filter[rewriting tag names]:command' \
'--subdirectory-filter[Only look at the history which touches the given subdirectory]:directory:_directories' \
'--prune-empty[Some kind of filters will generate empty commits, that left the tree untouched]' \
'--original[set the namespace where the original commits will be stored]:namespace' \
'-d[temprary directory]:directory:_directories' \
'(-f --force)'{-f,--force}'[force to use temporary directory or refs/original/]' \
'--::rest:->rest' && ret=0
case $state in
(rest)
declare -a arguments
arguments=('*::revision:__git_revisions')
_arguments -C \
$arguments && ret=0
;;
esac
}
(( $+functions[_git-submodule] )) ||
_git-submodule () {
local curcontext=$curcontext state line
declare -A opt_args
_arguments -C \
'(-q --quiet)'{-q,--quiet}'[Only print error messages]' \
':command:->command' \
'*::options:->options' && ret=0
case $state in
(command)
declare -a commands
commands=(
'add:Add the given repository as a submodule at the given path to the changeset to be commtied next to the current project'
'status:Show the status of the submodules'
'init:Initialize the submodules'
'update:Update the registred submodules'
'summary:Show commit summary between the given commit and working tree/index'
'foreach:Evaluates an arbitrary shell command in each checked out submodule'
'sync:Synchronize submodules')
_describe -t commands command commands && ret=0
;;
(options)
declare -a arguments
if [[ $line[1] == (add) ]]; then
arguments+=(
'(-b --branch)'{-b,-branch}'[Branch of repository to add as submodule]:branch:__git_branch_names'
'(-f --force)'{-f,--force}'[force overwrite of existing files]')
fi
if [[ $line[1] == (summary) ]]; then
arguments+=(
'--files[This command compares the commit in the index with that in the submodule HEAD when this iption is used]'
'(-n --summary-limit)'{-n,--summary-limit}'[Limit the summary size]')
fi
if [[ $line[1] == (status|summary) ]]; then
arguments+=(
'--cached[the commit stored in the index is used instead]')
fi
if [[ $line[1] == (update) ]]; then
arguments+=(
'--merge[Merge the commit recorded in the superproject into the current branch of the submodule]'
'--rebase[Rebase the current branch onto the commit recoreded in the superproject]'
'--init[automatically initialize the submodule]'
'(-N --no-fetch)'{-N,--no-fetch}'[Do not fetch new objects from the remote site]')
fi
if [[ $line[1] == (add|update) ]]; then
arguments+=(
'--reference[reference repository]:repository:_directories')
fi
if [[ $line[1] == (foreach|update|status) ]]; then
arguments+=(
'--recursive[Traverse submodules recursively]')
fi
case $line[1] in
(add)
arguments+=(':url:_urls')
;;
esac
arguments+=('::directory:_directories')
_arguments -C \
$arguments && ret=0
case $state in
(subdirectory)
_alternative \
'sub-directories:sub-directory:_directories' \
'urls: :_urls' && ret=0
;;
esac
;;
esac
}
__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 () {
autoload +X _git
# setting for checkout branch stack
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
# setting for submodule
eval "function _git () { ${functions[_git]/interoperability_commands=\(/interoperability_commands=('filter-branch:Rewrite branches' 'submodule:Initialize, update or inspect submodules' 'now:Record changes to the repository with a log message from time now and diff' } }"
}
my__git_initialize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment