2012-11-18 12:08:08 +01:00
|
|
|
#compdef git gitk
|
|
|
|
|
|
|
|
# zsh completion wrapper for git
|
|
|
|
#
|
2020-10-28 03:07:12 +01:00
|
|
|
# Copyright (c) 2012-2020 Felipe Contreras <felipe.contreras@gmail.com>
|
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
|
|
|
#
|
2020-10-25 04:13:16 +01:00
|
|
|
# The recommended way to install this script is to make a copy of it as a
|
|
|
|
# file named '_git' inside any directory in your fpath.
|
|
|
|
#
|
|
|
|
# For example, create a directory '~/.zsh/', copy this file 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)
|
2020-10-25 04:13:18 +01:00
|
|
|
#
|
|
|
|
# You need git's bash completion script installed. By default bash-completion's
|
2020-10-28 03:06:49 +01:00
|
|
|
# location will be used (e.g. pkg-config --variable=completionsdir bash-completion).
|
2020-10-25 04:13:18 +01:00
|
|
|
#
|
|
|
|
# If your bash completion script is somewhere else, you can specify the
|
|
|
|
# location in your ~/.zshrc:
|
|
|
|
#
|
|
|
|
# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
|
|
|
|
#
|
2012-11-18 12:08:08 +01:00
|
|
|
|
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
|
2020-10-28 03:06:49 +01:00
|
|
|
local e bash_completion
|
|
|
|
|
|
|
|
bash_completion=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) ||
|
|
|
|
bash_completion='/usr/share/bash-completion/completions/'
|
|
|
|
|
2013-05-25 05:31:44 +02:00
|
|
|
locations=(
|
2020-10-25 04:13:19 +01:00
|
|
|
"$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
|
2020-10-28 03:06:49 +01:00
|
|
|
"$HOME/.local/share/bash-completion/completions/git"
|
|
|
|
"$bash_completion/git"
|
|
|
|
'/etc/bash_completion.d/git' # old debian
|
2013-05-25 05:31:44 +02:00
|
|
|
)
|
|
|
|
for e in $locations; do
|
|
|
|
test -f $e && script="$e" && break
|
|
|
|
done
|
|
|
|
fi
|
2020-10-28 03:06:55 +01:00
|
|
|
|
|
|
|
local old_complete="$functions[complete]"
|
|
|
|
functions[complete]=:
|
2018-06-11 20:20:53 +02:00
|
|
|
GIT_SOURCING_ZSH_COMPLETION=y . "$script"
|
2020-10-28 03:06:55 +01:00
|
|
|
functions[complete]="$old_complete"
|
2012-11-18 12:08:08 +01:00
|
|
|
|
|
|
|
__gitcomp ()
|
|
|
|
{
|
|
|
|
emulate -L zsh
|
|
|
|
|
|
|
|
local cur_="${3-$cur}"
|
|
|
|
|
|
|
|
case "$cur_" in
|
|
|
|
--*=)
|
|
|
|
;;
|
2020-10-28 03:06:54 +01:00
|
|
|
--no-*)
|
|
|
|
local c IFS=$' \t\n'
|
|
|
|
local -a array
|
|
|
|
for c in ${=1}; do
|
|
|
|
if [[ $c == "--" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
c="$c${4-}"
|
|
|
|
case $c in
|
|
|
|
--*=|*.) ;;
|
|
|
|
*) c="$c " ;;
|
|
|
|
esac
|
|
|
|
array+=("$c")
|
|
|
|
done
|
|
|
|
compset -P '*[=:]'
|
|
|
|
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
|
|
|
|
;;
|
2012-11-18 12:08:08 +01:00
|
|
|
*)
|
|
|
|
local c IFS=$' \t\n'
|
|
|
|
local -a array
|
|
|
|
for c in ${=1}; do
|
2020-10-28 03:06:54 +01:00
|
|
|
if [[ $c == "--" ]]; then
|
|
|
|
c="--no-...${4-}"
|
|
|
|
array+=("$c ")
|
|
|
|
break
|
|
|
|
fi
|
2012-11-18 12:08:08 +01:00
|
|
|
c="$c${4-}"
|
|
|
|
case $c in
|
2020-10-28 03:07:07 +01:00
|
|
|
--*=|*.) ;;
|
2012-11-18 12:08:08 +01:00
|
|
|
*) c="$c " ;;
|
|
|
|
esac
|
|
|
|
array+=("$c")
|
|
|
|
done
|
|
|
|
compset -P '*[=:]'
|
|
|
|
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
completion: fill COMPREPLY directly when completing refs
__gitcomp_nl() iterates over all the possible completion words it gets
as argument
- filtering matching words,
- appending a trailing space to each matching word (in all but two
cases),
- prepending a prefix to each matching word (when completing words
after e.g. '--option=<TAB>' or 'master..<TAB>'), and
- adding each matching word to the COMPREPLY array.
This takes a while when a lot of refs are passed to __gitcomp_nl().
The previous changes in this series ensure that __git_refs() lists
only refs matching the current word to be completed, making a second
filtering in __gitcomp_nl() redundant.
Adding the necessary prefix and suffix could be done in __git_refs()
as well:
- When refs come from 'git for-each-ref', then that prefix and
suffix could be added much more efficiently using a 'git
for-each-ref' format containing said prefix and suffix. Care
should be taken, though, because that prefix might contain
'for-each-ref' format specifiers as part of the left hand side of
a '..' range or '...' symmetric difference notation or
fetch/push/etc. refspec, e.g. 'git log "evil-%(refname)..br<TAB>'.
Doubling every '%' in the prefix will prevent 'git for-each-ref'
from interpolating any of those contained specifiers.
- When refs come from 'git ls-remote', then that prefix and suffix
can be added in the shell loop that has to process 'git
ls-remote's output anyway.
- Finally, the prefix and suffix can be added to that handful of
potentially matching symbolic and pseudo refs right away in the
shell loop listing them.
And then all what is still left to do is to assign a bunch of
newline-separated words to a shell array, which can be done without a
shell loop iterating over each word, basically making all of
__gitcomp_nl() unnecessary for refs completion.
Add the helper function __gitcomp_direct() to fill the COMPREPLY array
with prefiltered and preprocessed words without any additional
processing, without a shell loop, with just one single compound
assignment. Modify __git_refs() to accept prefix and suffix
parameters and add them to each and every listed ref as described
above. Modify __git_complete_refs() to pass the prefix and suffix
parameters to __git_refs() and to feed __git_refs()'s output to
__gitcomp_direct() instead of __gitcomp_nl().
This speeds up refs completion when there are a lot of refs matching
the current word to be completed. Listing all branches for completion
in a repo with 100k local branches, all packed, best of five:
On Linux, near the beginning of this series, for reference:
$ time __git_complete_refs
real 0m2.028s
user 0m1.692s
sys 0m0.344s
Before this patch:
real 0m1.135s
user 0m1.112s
sys 0m0.024s
After:
real 0m0.367s
user 0m0.352s
sys 0m0.020s
On Windows, near the beginning:
real 0m13.078s
user 0m1.609s
sys 0m0.060s
Before this patch:
real 0m2.093s
user 0m1.641s
sys 0m0.060s
After:
real 0m0.683s
user 0m0.203s
sys 0m0.076s
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-23 16:29:22 +01:00
|
|
|
__gitcomp_direct ()
|
|
|
|
{
|
|
|
|
emulate -L zsh
|
|
|
|
|
|
|
|
compset -P '*[=:]'
|
2020-10-28 03:06:59 +01:00
|
|
|
compadd -Q -S '' -- ${(f)1} && _ret=0
|
completion: fill COMPREPLY directly when completing refs
__gitcomp_nl() iterates over all the possible completion words it gets
as argument
- filtering matching words,
- appending a trailing space to each matching word (in all but two
cases),
- prepending a prefix to each matching word (when completing words
after e.g. '--option=<TAB>' or 'master..<TAB>'), and
- adding each matching word to the COMPREPLY array.
This takes a while when a lot of refs are passed to __gitcomp_nl().
The previous changes in this series ensure that __git_refs() lists
only refs matching the current word to be completed, making a second
filtering in __gitcomp_nl() redundant.
Adding the necessary prefix and suffix could be done in __git_refs()
as well:
- When refs come from 'git for-each-ref', then that prefix and
suffix could be added much more efficiently using a 'git
for-each-ref' format containing said prefix and suffix. Care
should be taken, though, because that prefix might contain
'for-each-ref' format specifiers as part of the left hand side of
a '..' range or '...' symmetric difference notation or
fetch/push/etc. refspec, e.g. 'git log "evil-%(refname)..br<TAB>'.
Doubling every '%' in the prefix will prevent 'git for-each-ref'
from interpolating any of those contained specifiers.
- When refs come from 'git ls-remote', then that prefix and suffix
can be added in the shell loop that has to process 'git
ls-remote's output anyway.
- Finally, the prefix and suffix can be added to that handful of
potentially matching symbolic and pseudo refs right away in the
shell loop listing them.
And then all what is still left to do is to assign a bunch of
newline-separated words to a shell array, which can be done without a
shell loop iterating over each word, basically making all of
__gitcomp_nl() unnecessary for refs completion.
Add the helper function __gitcomp_direct() to fill the COMPREPLY array
with prefiltered and preprocessed words without any additional
processing, without a shell loop, with just one single compound
assignment. Modify __git_refs() to accept prefix and suffix
parameters and add them to each and every listed ref as described
above. Modify __git_complete_refs() to pass the prefix and suffix
parameters to __git_refs() and to feed __git_refs()'s output to
__gitcomp_direct() instead of __gitcomp_nl().
This speeds up refs completion when there are a lot of refs matching
the current word to be completed. Listing all branches for completion
in a repo with 100k local branches, all packed, best of five:
On Linux, near the beginning of this series, for reference:
$ time __git_complete_refs
real 0m2.028s
user 0m1.692s
sys 0m0.344s
Before this patch:
real 0m1.135s
user 0m1.112s
sys 0m0.024s
After:
real 0m0.367s
user 0m0.352s
sys 0m0.020s
On Windows, near the beginning:
real 0m13.078s
user 0m1.609s
sys 0m0.060s
Before this patch:
real 0m2.093s
user 0m1.641s
sys 0m0.060s
After:
real 0m0.683s
user 0m0.203s
sys 0m0.076s
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-23 16:29:22 +01:00
|
|
|
}
|
|
|
|
|
2012-11-18 12:08:08 +01:00
|
|
|
__gitcomp_nl ()
|
|
|
|
{
|
|
|
|
emulate -L zsh
|
|
|
|
|
|
|
|
compset -P '*[=:]'
|
2020-10-28 03:06:58 +01:00
|
|
|
compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
|
2012-11-18 12:08:08 +01:00
|
|
|
}
|
|
|
|
|
2020-10-28 03:07:03 +01:00
|
|
|
__gitcomp_file ()
|
2014-01-05 11:18:03 +01:00
|
|
|
{
|
2020-10-28 03:07:03 +01:00
|
|
|
emulate -L zsh
|
|
|
|
|
2020-12-01 01:54:31 +01:00
|
|
|
compset -P '*[=:]'
|
2020-10-28 03:07:03 +01:00
|
|
|
compadd -f -p "${2-}" -- ${(f)1} && _ret=0
|
2014-01-05 11:18:03 +01:00
|
|
|
}
|
|
|
|
|
2020-10-28 03:07:03 +01:00
|
|
|
__gitcomp_direct_append ()
|
completion: fill COMPREPLY directly when completing paths
During git-aware path completion, when a lot of path components have
to be listed, a significant amount of time is spent in
__gitcomp_file(), or more accurately in the shell loop of
__gitcompappend(), iterating over all the path components filtering
path components matching the current word to be completed, adding
prefix path components, and placing the resulting matching paths into
the COMPREPLY array.
Now, a previous patch in this series made 'git ls-files' and 'git
diff-index' list only paths matching the current word to be completed,
so an additional filtering in __gitcomp_file() is not necessary
anymore. Adding the prefix path components could be done much more
efficiently in __git_index_files()'s 'awk' script while stripping
trailing path components and removing duplicates and quoting. And
then the resulting paths won't require any more filtering or
processing before being handed over to Bash, so we could fill the
COMPREPLY array directly.
Unfortunately, we can't simply use the __gitcomp_direct() helper
function to do that, because __gitcomp_file() does one additional
thing: it tells Bash that we are doing filename completion, so the
shell will kindly do four important things for us:
1. Append a trailing space to all filenames.
2. Append a trailing '/' to all directory names.
3. Escape any meta, globbing, separator, etc. characters.
4. List only the current path component when listing possible
completions (i.e. 'dir/subdir/f<TAB>' will list 'file1', 'file2',
etc. instead of the whole 'dir/subdir/file1',
'dir/subdir/file2').
While we could let __git_index_files()'s 'awk' script take care of the
first two points, the third one gets tricky, and we absolutely need
the shell's support for the fourth.
Add the helper function __gitcomp_file_direct(), which, just like
__gitcomp_direct(), fills the COMPREPLY array with prefiltered and
preprocessed paths without any additional processing, without a shell
loop, with just one single compound assignment, and, similar to
__gitcomp_file(), tells Bash and ZSH that we are doing filename
completion. Extend __git_index_files()'s 'awk' script a bit to
prepend any prefix path components to all listed paths. Finally,
modify __git_complete_index_file() to feed __git_index_files()'s
output to ___gitcomp_file_direct() instead of __gitcomp_file().
After this patch there is no shell loop left in the path completion
code path.
This speeds up path completion when there are a lot of paths matching
the current word to be completed. In a pathological repository with
100k files in a single directory, listing all those files:
Before this patch, best of five, using GNU awk on Linux:
$ time cur=dir/ __git_complete_index_file
real 0m0.983s
user 0m1.004s
sys 0m0.033s
After:
real 0m0.313s
user 0m0.341s
sys 0m0.029s
Difference: -68.2%
Speedup: 3.1x
To see the benefits of the whole patch series, the same command with
v2.17.0:
real 0m2.736s
user 0m2.472s
sys 0m0.610s
Difference: -88.6%
Speedup: 8.7x
Note that this patch changes the output of the __git_index_files()
helper function by unconditionally prepending the prefix path
components to every listed path. This would break users' completion
scriptlets that directly run:
__gitcomp_file "$(__git_index_files ...)" "$pfx" "$cur_"
because that would add the prefix path components once more.
However, __git_index_files() is kind of a "helper function of a helper
function", and users' completion scriptlets should have been using
__git_complete_index_file() for git-aware path completion in the first
place, so this is likely doesn't worth worrying about.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-04-17 00:42:36 +02:00
|
|
|
{
|
2020-10-28 03:07:03 +01:00
|
|
|
__gitcomp_direct "$@"
|
completion: fill COMPREPLY directly when completing paths
During git-aware path completion, when a lot of path components have
to be listed, a significant amount of time is spent in
__gitcomp_file(), or more accurately in the shell loop of
__gitcompappend(), iterating over all the path components filtering
path components matching the current word to be completed, adding
prefix path components, and placing the resulting matching paths into
the COMPREPLY array.
Now, a previous patch in this series made 'git ls-files' and 'git
diff-index' list only paths matching the current word to be completed,
so an additional filtering in __gitcomp_file() is not necessary
anymore. Adding the prefix path components could be done much more
efficiently in __git_index_files()'s 'awk' script while stripping
trailing path components and removing duplicates and quoting. And
then the resulting paths won't require any more filtering or
processing before being handed over to Bash, so we could fill the
COMPREPLY array directly.
Unfortunately, we can't simply use the __gitcomp_direct() helper
function to do that, because __gitcomp_file() does one additional
thing: it tells Bash that we are doing filename completion, so the
shell will kindly do four important things for us:
1. Append a trailing space to all filenames.
2. Append a trailing '/' to all directory names.
3. Escape any meta, globbing, separator, etc. characters.
4. List only the current path component when listing possible
completions (i.e. 'dir/subdir/f<TAB>' will list 'file1', 'file2',
etc. instead of the whole 'dir/subdir/file1',
'dir/subdir/file2').
While we could let __git_index_files()'s 'awk' script take care of the
first two points, the third one gets tricky, and we absolutely need
the shell's support for the fourth.
Add the helper function __gitcomp_file_direct(), which, just like
__gitcomp_direct(), fills the COMPREPLY array with prefiltered and
preprocessed paths without any additional processing, without a shell
loop, with just one single compound assignment, and, similar to
__gitcomp_file(), tells Bash and ZSH that we are doing filename
completion. Extend __git_index_files()'s 'awk' script a bit to
prepend any prefix path components to all listed paths. Finally,
modify __git_complete_index_file() to feed __git_index_files()'s
output to ___gitcomp_file_direct() instead of __gitcomp_file().
After this patch there is no shell loop left in the path completion
code path.
This speeds up path completion when there are a lot of paths matching
the current word to be completed. In a pathological repository with
100k files in a single directory, listing all those files:
Before this patch, best of five, using GNU awk on Linux:
$ time cur=dir/ __git_complete_index_file
real 0m0.983s
user 0m1.004s
sys 0m0.033s
After:
real 0m0.313s
user 0m0.341s
sys 0m0.029s
Difference: -68.2%
Speedup: 3.1x
To see the benefits of the whole patch series, the same command with
v2.17.0:
real 0m2.736s
user 0m2.472s
sys 0m0.610s
Difference: -88.6%
Speedup: 8.7x
Note that this patch changes the output of the __git_index_files()
helper function by unconditionally prepending the prefix path
components to every listed path. This would break users' completion
scriptlets that directly run:
__gitcomp_file "$(__git_index_files ...)" "$pfx" "$cur_"
because that would add the prefix path components once more.
However, __git_index_files() is kind of a "helper function of a helper
function", and users' completion scriptlets should have been using
__git_complete_index_file() for git-aware path completion in the first
place, so this is likely doesn't worth worrying about.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-04-17 00:42:36 +02:00
|
|
|
}
|
|
|
|
|
2020-10-28 03:07:03 +01:00
|
|
|
__gitcomp_nl_append ()
|
2013-03-05 09:43:55 +01:00
|
|
|
{
|
2020-10-28 03:07:03 +01:00
|
|
|
__gitcomp_nl "$@"
|
|
|
|
}
|
2013-03-05 09:43:55 +01:00
|
|
|
|
2020-10-28 03:07:03 +01:00
|
|
|
__gitcomp_file_direct ()
|
|
|
|
{
|
|
|
|
__gitcomp_file "$1" ""
|
2013-03-05 09:43:55 +01:00
|
|
|
}
|
|
|
|
|
2020-10-28 03:07:08 +01:00
|
|
|
_git_zsh ()
|
|
|
|
{
|
|
|
|
__gitcomp "v1.1"
|
|
|
|
}
|
|
|
|
|
2020-10-28 03:07:04 +01:00
|
|
|
__git_complete_command ()
|
|
|
|
{
|
|
|
|
emulate -L zsh
|
|
|
|
|
|
|
|
local command="$1"
|
|
|
|
local completion_func="_git_${command//-/_}"
|
|
|
|
if (( $+functions[$completion_func] )); then
|
|
|
|
emulate ksh -c $completion_func
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2020-10-28 03:07:04 +01:00
|
|
|
__git_complete_command "$command" && return
|
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
|
|
|
|
|
|
|
local expansion=$(__git_aliased_command "$command")
|
|
|
|
if [ -n "$expansion" ]; then
|
2014-04-09 20:50:04 +02:00
|
|
|
words[1]=$expansion
|
2020-10-28 03:07:04 +01:00
|
|
|
__git_complete_command "$expansion"
|
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
|
|
|
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'
|
2020-04-17 09:11:04 +02:00
|
|
|
restore:'restore working tree files'
|
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
|
|
|
rm:'remove files from the working tree and from the index'
|
|
|
|
show:'show various types of objects'
|
|
|
|
status:'show the working tree status'
|
2020-04-17 09:11:04 +02:00
|
|
|
switch:'switch branches'
|
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
|
|
|
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
|
2020-10-28 03:07:06 +01:00
|
|
|
list=(${${(0)"$(git config -z --get-regexp '^alias\.*')"}#alias.})
|
|
|
|
list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"})
|
|
|
|
_describe -t alias-commands 'aliases' list && _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_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)
|
2020-10-28 03:07:05 +01:00
|
|
|
_tags common-commands alias-commands all-commands
|
|
|
|
while _tags; do
|
|
|
|
_requested common-commands && __git_zsh_cmd_common
|
|
|
|
_requested alias-commands && __git_zsh_cmd_alias
|
|
|
|
_requested all-commands && __git_zsh_cmd_all
|
|
|
|
let _ret || break
|
|
|
|
done
|
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
|
|
|
;;
|
|
|
|
(arg)
|
2021-06-01 22:52:29 +02:00
|
|
|
local command="${words[1]}" __git_dir __git_cmd_idx=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 (( $+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
|
2020-10-28 03:06:51 +01:00
|
|
|
elif (( $+functions[__${service}_main] )); then
|
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
|
|
|
emulate ksh -c __${service}_main
|
2020-10-28 03:06:51 +01:00
|
|
|
elif (( $+functions[_${service}] )); then
|
|
|
|
emulate ksh -c _${service}
|
|
|
|
elif (( $+functions[_${service//-/_}] )); then
|
|
|
|
emulate ksh -c _${service//-/_}
|
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
|
|
|
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
|