2012-11-18 12:08:08 +01:00
|
|
|
#compdef git gitk
|
|
|
|
|
|
|
|
# zsh completion wrapper for git
|
|
|
|
#
|
complete: zsh: use zsh completion for the main cmd
So that we can have a nice zsh completion output:
% git <tab>
add -- add file contents to the index
bisect -- find by binary search the change that introduced a bug
branch -- list, create, or delete branches
checkout -- checkout a branch or paths to the working tree
clone -- clone a repository into a new directory
commit -- record changes to the repository
diff -- show changes between commits, commit and working tree, etc
fetch -- download objects and refs from another repository
grep -- print lines matching a pattern
init -- create an empty Git repository or reinitialize an existing one
log -- show commit logs
merge -- join two or more development histories together
mv -- move or rename a file, a directory, or a symlink
pull -- fetch from and merge with another repository or a local branch
push -- update remote refs along with associated objects
rebase -- forward-port local commits to the updated upstream head
reset -- reset current HEAD to the specified state
rm -- remove files from the working tree and from the index
show -- show various types of objects
status -- show the working tree status
tag -- create, list, delete or verify a tag object signed with GPG
And other niceties, like 'git --git-dir=<tab>' showing only directories.
For the rest, the bash completion stuff is still used.
Also, add my copyright, since this more than a thin wrapper.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-27 22:34:06 +02:00
|
|
|
# Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
|
|
|
|
#
|
2013-05-25 05:31:44 +02:00
|
|
|
# You need git's bash completion script installed somewhere, by default it
|
|
|
|
# would be the location bash-completion uses.
|
2012-11-18 12:08:08 +01:00
|
|
|
#
|
2013-05-25 05:31:44 +02:00
|
|
|
# If your script is somewhere else, you can configure it on your ~/.zshrc:
|
2012-11-18 12:08:08 +01:00
|
|
|
#
|
|
|
|
# zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
|
|
|
|
#
|
2013-05-25 05:31:44 +02:00
|
|
|
# The recommended way to install this script is to copy to '~/.zsh/_git', and
|
|
|
|
# then add the following to your ~/.zshrc file:
|
2012-11-18 12:08:08 +01:00
|
|
|
#
|
2013-05-25 05:31:44 +02:00
|
|
|
# fpath=(~/.zsh $fpath)
|
2012-11-18 12:08:08 +01:00
|
|
|
|
|
|
|
complete ()
|
|
|
|
{
|
|
|
|
# do nothing
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
complete: zsh: use zsh completion for the main cmd
So that we can have a nice zsh completion output:
% git <tab>
add -- add file contents to the index
bisect -- find by binary search the change that introduced a bug
branch -- list, create, or delete branches
checkout -- checkout a branch or paths to the working tree
clone -- clone a repository into a new directory
commit -- record changes to the repository
diff -- show changes between commits, commit and working tree, etc
fetch -- download objects and refs from another repository
grep -- print lines matching a pattern
init -- create an empty Git repository or reinitialize an existing one
log -- show commit logs
merge -- join two or more development histories together
mv -- move or rename a file, a directory, or a symlink
pull -- fetch from and merge with another repository or a local branch
push -- update remote refs along with associated objects
rebase -- forward-port local commits to the updated upstream head
reset -- reset current HEAD to the specified state
rm -- remove files from the working tree and from the index
show -- show various types of objects
status -- show the working tree status
tag -- create, list, delete or verify a tag object signed with GPG
And other niceties, like 'git --git-dir=<tab>' showing only directories.
For the rest, the bash completion stuff is still used.
Also, add my copyright, since this more than a thin wrapper.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-27 22:34:06 +02:00
|
|
|
zstyle -T ':completion:*:*:git:*' tag-order && \
|
|
|
|
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
|
|
|
|
|
2012-11-18 12:08:08 +01:00
|
|
|
zstyle -s ":completion:*:*:git:*" script script
|
2013-05-25 05:31:44 +02:00
|
|
|
if [ -z "$script" ]; then
|
|
|
|
local -a locations
|
|
|
|
local e
|
|
|
|
locations=(
|
|
|
|
'/etc/bash_completion.d/git' # fedora, old debian
|
|
|
|
'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
|
|
|
|
'/usr/share/bash-completion/git' # gentoo
|
|
|
|
$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
|
|
|
|
)
|
|
|
|
for e in $locations; do
|
|
|
|
test -f $e && script="$e" && break
|
|
|
|
done
|
|
|
|
fi
|
2012-11-18 12:08:08 +01:00
|
|
|
ZSH_VERSION='' . "$script"
|
|
|
|
|
|
|
|
__gitcomp ()
|
|
|
|
{
|
|
|
|
emulate -L zsh
|
|
|
|
|
|
|
|
local cur_="${3-$cur}"
|
|
|
|
|
|
|
|
case "$cur_" in
|
|
|
|
--*=)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
local c IFS=$' \t\n'
|
|
|
|
local -a array
|
|
|
|
for c in ${=1}; do
|
|
|
|
c="$c${4-}"
|
|
|
|
case $c in
|
|
|
|
--*=*|*.) ;;
|
|
|
|
*) c="$c " ;;
|
|
|
|
esac
|
|
|
|
array+=("$c")
|
|
|
|
done
|
|
|
|
compset -P '*[=:]'
|
|
|
|
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
__gitcomp_nl ()
|
|
|
|
{
|
|
|
|
emulate -L zsh
|
|
|
|
|
|
|
|
local IFS=$'\n'
|
|
|
|
compset -P '*[=:]'
|
|
|
|
compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
|
|
|
|
}
|
|
|
|
|
2013-03-05 09:43:55 +01:00
|
|
|
__gitcomp_file ()
|
|
|
|
{
|
|
|
|
emulate -L zsh
|
|
|
|
|
|
|
|
local IFS=$'\n'
|
|
|
|
compset -P '*[=:]'
|
|
|
|
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
|
|
|
|
}
|
|
|
|
|
complete: zsh: use zsh completion for the main cmd
So that we can have a nice zsh completion output:
% git <tab>
add -- add file contents to the index
bisect -- find by binary search the change that introduced a bug
branch -- list, create, or delete branches
checkout -- checkout a branch or paths to the working tree
clone -- clone a repository into a new directory
commit -- record changes to the repository
diff -- show changes between commits, commit and working tree, etc
fetch -- download objects and refs from another repository
grep -- print lines matching a pattern
init -- create an empty Git repository or reinitialize an existing one
log -- show commit logs
merge -- join two or more development histories together
mv -- move or rename a file, a directory, or a symlink
pull -- fetch from and merge with another repository or a local branch
push -- update remote refs along with associated objects
rebase -- forward-port local commits to the updated upstream head
reset -- reset current HEAD to the specified state
rm -- remove files from the working tree and from the index
show -- show various types of objects
status -- show the working tree status
tag -- create, list, delete or verify a tag object signed with GPG
And other niceties, like 'git --git-dir=<tab>' showing only directories.
For the rest, the bash completion stuff is still used.
Also, add my copyright, since this more than a thin wrapper.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-27 22:34:06 +02:00
|
|
|
__git_zsh_bash_func ()
|
|
|
|
{
|
|
|
|
emulate -L ksh
|
|
|
|
|
|
|
|
local command=$1
|
|
|
|
|
|
|
|
local completion_func="_git_${command//-/_}"
|
|
|
|
declare -f $completion_func >/dev/null && $completion_func && return
|
|
|
|
|
|
|
|
local expansion=$(__git_aliased_command "$command")
|
|
|
|
if [ -n "$expansion" ]; then
|
|
|
|
completion_func="_git_${expansion//-/_}"
|
|
|
|
declare -f $completion_func >/dev/null && $completion_func
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
__git_zsh_cmd_common ()
|
|
|
|
{
|
|
|
|
local -a list
|
|
|
|
list=(
|
|
|
|
add:'add file contents to the index'
|
|
|
|
bisect:'find by binary search the change that introduced a bug'
|
|
|
|
branch:'list, create, or delete branches'
|
|
|
|
checkout:'checkout a branch or paths to the working tree'
|
|
|
|
clone:'clone a repository into a new directory'
|
|
|
|
commit:'record changes to the repository'
|
|
|
|
diff:'show changes between commits, commit and working tree, etc'
|
|
|
|
fetch:'download objects and refs from another repository'
|
|
|
|
grep:'print lines matching a pattern'
|
|
|
|
init:'create an empty Git repository or reinitialize an existing one'
|
|
|
|
log:'show commit logs'
|
|
|
|
merge:'join two or more development histories together'
|
|
|
|
mv:'move or rename a file, a directory, or a symlink'
|
|
|
|
pull:'fetch from and merge with another repository or a local branch'
|
|
|
|
push:'update remote refs along with associated objects'
|
|
|
|
rebase:'forward-port local commits to the updated upstream head'
|
|
|
|
reset:'reset current HEAD to the specified state'
|
|
|
|
rm:'remove files from the working tree and from the index'
|
|
|
|
show:'show various types of objects'
|
|
|
|
status:'show the working tree status'
|
|
|
|
tag:'create, list, delete or verify a tag object signed with GPG')
|
|
|
|
_describe -t common-commands 'common commands' list && _ret=0
|
|
|
|
}
|
|
|
|
|
|
|
|
__git_zsh_cmd_alias ()
|
|
|
|
{
|
|
|
|
local -a list
|
|
|
|
list=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$'\n'*})
|
|
|
|
_describe -t alias-commands 'aliases' list $* && _ret=0
|
|
|
|
}
|
|
|
|
|
|
|
|
__git_zsh_cmd_all ()
|
|
|
|
{
|
|
|
|
local -a list
|
|
|
|
emulate ksh -c __git_compute_all_commands
|
|
|
|
list=( ${=__git_all_commands} )
|
|
|
|
_describe -t all-commands 'all commands' list && _ret=0
|
|
|
|
}
|
|
|
|
|
|
|
|
__git_zsh_main ()
|
|
|
|
{
|
|
|
|
local curcontext="$curcontext" state state_descr line
|
|
|
|
typeset -A opt_args
|
|
|
|
local -a orig_words
|
|
|
|
|
|
|
|
orig_words=( ${words[@]} )
|
|
|
|
|
|
|
|
_arguments -C \
|
|
|
|
'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
|
|
|
|
'(-p --paginate)--no-pager[do not pipe git output into a pager]' \
|
|
|
|
'--git-dir=-[set the path to the repository]: :_directories' \
|
|
|
|
'--bare[treat the repository as a bare repository]' \
|
|
|
|
'(- :)--version[prints the git suite version]' \
|
|
|
|
'--exec-path=-[path to where your core git programs are installed]:: :_directories' \
|
|
|
|
'--html-path[print the path where git''s HTML documentation is installed]' \
|
|
|
|
'--info-path[print the path where the Info files are installed]' \
|
|
|
|
'--man-path[print the manpath (see `man(1)`) for the man pages]' \
|
|
|
|
'--work-tree=-[set the path to the working tree]: :_directories' \
|
|
|
|
'--namespace=-[set the git namespace]' \
|
|
|
|
'--no-replace-objects[do not use replacement refs to replace git objects]' \
|
|
|
|
'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \
|
|
|
|
'(-): :->command' \
|
|
|
|
'(-)*:: :->arg' && return
|
|
|
|
|
|
|
|
case $state in
|
|
|
|
(command)
|
|
|
|
_alternative \
|
|
|
|
'alias-commands:alias:__git_zsh_cmd_alias' \
|
|
|
|
'common-commands:common:__git_zsh_cmd_common' \
|
|
|
|
'all-commands:all:__git_zsh_cmd_all' && _ret=0
|
|
|
|
;;
|
|
|
|
(arg)
|
|
|
|
local command="${words[1]}" __git_dir
|
|
|
|
|
|
|
|
if (( $+opt_args[--bare] )); then
|
|
|
|
__git_dir='.'
|
|
|
|
else
|
|
|
|
__git_dir=${opt_args[--git-dir]}
|
|
|
|
fi
|
|
|
|
|
|
|
|
(( $+opt_args[--help] )) && command='help'
|
|
|
|
|
|
|
|
words=( ${orig_words[@]} )
|
|
|
|
|
|
|
|
__git_zsh_bash_func $command
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2012-11-18 12:08:08 +01:00
|
|
|
_git ()
|
|
|
|
{
|
|
|
|
local _ret=1
|
2013-04-27 22:34:05 +02:00
|
|
|
local cur cword prev
|
|
|
|
|
|
|
|
cur=${words[CURRENT]}
|
|
|
|
prev=${words[CURRENT-1]}
|
|
|
|
let cword=CURRENT-1
|
|
|
|
|
complete: zsh: use zsh completion for the main cmd
So that we can have a nice zsh completion output:
% git <tab>
add -- add file contents to the index
bisect -- find by binary search the change that introduced a bug
branch -- list, create, or delete branches
checkout -- checkout a branch or paths to the working tree
clone -- clone a repository into a new directory
commit -- record changes to the repository
diff -- show changes between commits, commit and working tree, etc
fetch -- download objects and refs from another repository
grep -- print lines matching a pattern
init -- create an empty Git repository or reinitialize an existing one
log -- show commit logs
merge -- join two or more development histories together
mv -- move or rename a file, a directory, or a symlink
pull -- fetch from and merge with another repository or a local branch
push -- update remote refs along with associated objects
rebase -- forward-port local commits to the updated upstream head
reset -- reset current HEAD to the specified state
rm -- remove files from the working tree and from the index
show -- show various types of objects
status -- show the working tree status
tag -- create, list, delete or verify a tag object signed with GPG
And other niceties, like 'git --git-dir=<tab>' showing only directories.
For the rest, the bash completion stuff is still used.
Also, add my copyright, since this more than a thin wrapper.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-27 22:34:06 +02:00
|
|
|
if (( $+functions[__${service}_zsh_main] )); then
|
|
|
|
__${service}_zsh_main
|
|
|
|
else
|
|
|
|
emulate ksh -c __${service}_main
|
|
|
|
fi
|
2013-04-27 22:34:05 +02:00
|
|
|
|
2013-05-03 23:35:50 +02:00
|
|
|
let _ret && _default && _ret=0
|
2012-11-18 12:08:08 +01:00
|
|
|
return _ret
|
|
|
|
}
|
|
|
|
|
|
|
|
_git
|