Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] _git: enable completion for arguments to git aliases
- X-seq: zsh-workers 24413
- From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxxxxx>
- Subject: [PATCH] _git: enable completion for arguments to git aliases
- Date: Sun, 20 Jan 2008 22:17:43 +0100
- Mail-followup-to: zsh workers <zsh-workers@xxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
The following implements what the subject suggests. I'm not convinced,
that the way I did is the best there is. So comments are welcome.
So, considering, you got an alias for checkout named 'co', you get the
completions you would expect for checkout when trying: git co <TAB>.
Also, I "fixed" up some places, where single single quotes where used
in double quotes, which confused vim's syntax highlighting quite a
bit.
Last but not least, this fixes a bug in '--date=' completions (for eg.
git log --date=<TAB>).
Regards, Frank
Index: Completion/Unix/Command/_git
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_git,v
retrieving revision 1.53
diff -u -r1.53 _git
--- Completion/Unix/Command/_git 3 Dec 2007 02:43:28 -0000 1.53
+++ Completion/Unix/Command/_git 20 Jan 2008 21:16:19 -0000
@@ -164,7 +164,7 @@
'revert:revert existing commit'
'rm:remove files from the working tree and from the index'
'show-branch:show branches and their commits'
- "status:show working-tree's status"
+ 'status:show working-tree'\''s status'
'tag:create tag object signed with GPG'
'verify-tag:check GPG signature of a tag')
@@ -225,7 +225,7 @@
'show-ref:list references in a local repository'
'symbolic-ref:read and modify symbolic references'
'tar-tree:create tar archive of the files in the named tree'
- "unpack-file:create temporary file with blob's contents"
+ 'unpack-file:create temporary file with blob'\''s contents'
'unpack-objects:unpack objects out of packed archive'
'update-ref:update object name stored in a reference safely'
'update-server-info:update auxiliary information on a dumb server'
@@ -665,7 +665,7 @@
(add)
_arguments \
'*'{--track,-t}'[track given branch instead of default glob refspec]:branch:__git_branch_names' \
- '(--master -m)'{--master,-m}"[set the remote's HEAD to point to given master branch]:branch:__git_branch_names" \
+ '(--master -m)'{--master,-m}'[set the remote'\''s HEAD to point to given master branch]:branch:__git_branch_names' \
'(--fetch -f)'{--fetch,-f}'[run git-fetch on the new remote after it has been created]' \
':branch name:__git_remotes' \
':url:_urls' && ret=0
@@ -936,7 +936,7 @@
(( $+functions[_git-quiltimport] )) ||
_git-quiltimport () {
_arguments \
- "--dry-run[check patches and warn if they can't be imported]" \
+ '--dry-run[check patches and warn if they can'\''t be imported]' \
'--author[default author name and email address to use for patches]' \
'--patches[set directory containing patches]:patch directory:_directories' && ret=0
}
@@ -1051,7 +1051,7 @@
'-v[show objects contained in pack]' \
'*:index file:_files -g "*.idx"' && ret=0
}
-
+
(( $+functions[_git-clone-pack] )) ||
_git-clone-pack () {
_arguments \
@@ -1456,7 +1456,7 @@
'-v[show SHA1 and commit subject line for each head]' \
$my_abbrev_arg \
- create \
- "-l[create the branch's reflog]" \
+ '-l[create the branch'\''s reflog]' \
'-f[force the creation of a new branch]' \
':branch-name:__git_branch_names' \
'::start-point:__git_revisions' \
@@ -1482,7 +1482,7 @@
local new_branch_reflog_arg
if (( words[(I)-b] > 0 )); then
- new_branch_reflog_arg="-l[create the new branch's reflog]"
+ new_branch_reflog_arg='-l[create the new branch'\''s reflog]'
fi
# TODO: This isnâ??t quite correct in regards of the handling of the â??--â??
@@ -2030,8 +2030,8 @@
_git-pack-refs () {
_arguments \
'--all[pack all refs]' \
- "( --no-prune)--prune[remove loose refs after packing them]" \
- "(--prune )--no-prune[don't remove loose refs after packing them]" && ret=0
+ '( --no-prune)--prune[remove loose refs after packing them]' \
+ '(--prune )--no-prune[don'\''t remove loose refs after packing them]' && ret=0
}
# TODO: something better
@@ -2276,7 +2276,7 @@
_git-rm () {
_arguments -S -A '-*' \
'-f[override the up-to-date check]' \
- "-n[don't actually remove the files, just show if they exist in the index]" \
+ '-n[don'\''t actually remove the files, just show if they exist in the index]' \
'-r[allow recursive removal when a leading directory-name is given]' \
'--cached[only remove files from the index]' \
'*:files:__git_cached_files' && ret=0
@@ -2342,7 +2342,7 @@
'rebase:fetch revs from SVN parent of HEAD and rebase current work on it'
'dcommit:commit diffs from given head onto SVN repository'
'log:output SVN log-messages'
- "find-rev:output git commit corresponding to the given SVN revision's hash"
+ 'find-rev:output git commit corresponding to the given SVN revision'\''s hash'
'set-tree:commit given commit or tree to SVN repository'
'show-ignore:output corresponding .gitignore file of svn:ignore'
'commit-diff:commit diff of two tree-ishs')
@@ -2982,7 +2982,7 @@
else
names=(
'core.fileMode:whether differences in the executable bit is relevant'
- "core.autocrlf:what type of conversion of CRLF's git should do"
+ 'core.autocrlf:what type of conversion of CRLF'\''s git should do'
'core.symlinks:whether symlinks are treated as special files or not'
'core.gitProxy:command to execute to establish a connection to remote server'
'core.ignoreStat:whether modification times of files are ignored'
@@ -3244,7 +3244,7 @@
booleans=(
{true,yes}':create ref files for branch heads'
- {false,no}":don't automatically create ref files")
+ {false,no}':don'\''t automatically create ref files')
_describe -t boolean 'boolean' booleans
;;
@@ -3260,7 +3260,7 @@
booleans=(
{true,yes}':warn if a ref name matches multiple refs'
{false,no}':ignore ambiguous ref names')
-
+
_describe -t boolean 'boolean' booleans
;;
((#i)core.compression)
@@ -3353,7 +3353,7 @@
settings=(
{true,yes}':enable basic rename detection'
- {false,no}":don't try to detect renames"
+ {false,no}':don'\''t try to detect renames'
{copies,copy}':detect file renames and copies')
_describe -t values 'rename-detection setting' settings
@@ -3387,7 +3387,7 @@
booleans=(
{true,yes}':enable the cvs server interface'
- {false,no}":don't enable the cvs server interface")
+ {false,no}':don'\''t enable the cvs server interface')
_describe -t booleans 'boolean' booleans
;;
@@ -3472,7 +3472,7 @@
declare -a booleans
booleans=(
- {true,yes}":don't use EPSV mode over FTP (for stupid servers)"
+ {true,yes}':don'\''t use EPSV mode over FTP (for stupid servers)'
{false,no}':use EPSV mode over FTP')
_describe -t booleans 'boolean' booleans
@@ -3495,7 +3495,7 @@
# TODO: Use (default) in more descriptions.
booleans=(
{true,yes}':include summaries in merge commit messages'
- {false,no}":don't add summaries to merge commit messages (default)")
+ {false,no}':don'\''t add summaries to merge commit messages (default)')
_describe -t booleans 'boolean' booleans
;;
@@ -3551,7 +3551,7 @@
declare -a opts
opts=(
- "--no-tags:don't fetch tags automatically"
+ '--no-tags:don'\''t fetch tags automatically'
'"":fetch tags as usual')
_describe -t tag-options 'tag retrieval' opts
@@ -3575,7 +3575,7 @@
booleas=(
{true,yes}':allow creation of delta-base-offset packs'
- {false,no}":don't create delta-base-offset packs")
+ {false,no}':don'\''t create delta-base-offset packs')
_describe -t booleans 'boolean' booleans
;;
@@ -3589,7 +3589,7 @@
((#i)tar.umask)
_alternative \
'number: :_guard "[0-7]#" "numeric mode"' \
- "values:special value:((user:\"use user's current umask\"))"
+ 'values:special value:((user:"use user'\''s current umask"))'
;;
((#i)user.email)
_email_addresses
@@ -3608,8 +3608,8 @@
declare -a booleans
booleans=(
- {true,yes}":git-receive-pack will deny a ref update that isn't a fast forward"
- {false,no}":allow a ref update that isn't a fast forward")
+ {true,yes}':git-receive-pack will deny a ref update that isn'\''t a fast forward'
+ {false,no}':allow a ref update that isn'\''t a fast forward')
_describe -t booleans 'boolean' booleans
;;
@@ -3637,7 +3637,7 @@
booleans=(
{true,yes}':bind the HTTP daemon to 127.0.0.1'
- {false,no}":don't bind the HTTP daemon to a specific address")
+ {false,no}':don'\''t bind the HTTP daemon to a specific address')
_describe -t booleans 'boolean' booleans
;;
@@ -3670,7 +3670,7 @@
booleans=(
{true,yes}':remap URLs and UUIDs for mirrors'
- {false,no}":don't remap URLs and UUIDs for mirrors")
+ {false,no}':don'\''t remap URLs and UUIDs for mirrors')
_describe -t booleans 'boolean' booleans
;;
@@ -3742,13 +3742,13 @@
__git_svn_revisions
;;
((#i)svn.merge)
- __git_boolean_settings false 'use merging strategies' "don't try to merge"
+ __git_boolean_settings false 'use merging strategies' 'don'\''t try to merge'
;;
((#i)svn.fetch-all)
__git_boolean_settings false 'undocumented'
;;
((#i)svn.stdin)
- __git_boolean_settings false 'read list of commits to commit from stdin' "don't necessarily read list of commits to commit from stdin"
+ __git_boolean_settings false 'read list of commits to commit from stdin' 'don'\''t necessarily read list of commits to commit from stdin'
;;
((#i)svn.strategy)
__git_merge_strategies
@@ -3769,7 +3769,7 @@
__git_boolean_settings false 'give output suitable for concatenation'
;;
((#i)svn.showcommit)
- __git_boolean_settings false 'output git commit SHA-1, as well' "don't output git commit SHA-1"
+ __git_boolean_settings false 'output git commit SHA-1, as well' 'don'\''t output git commit SHA-1'
;;
((#i)svn.online)
__git_boolean_settings false 'produce output similar to --pretty=oneline'
@@ -3820,7 +3820,7 @@
declare -A descriptions
- descriptions=(true $2 false "don't $2")
+ descriptions=(true $2 false 'don'\''t '"$2")
if (( $# > 2 )); then
descriptions[false]=$3
@@ -4085,9 +4085,9 @@
'--abbrev-commit[undocumented]'
'--full-history[undocumented]'
'--relative-date[show dates relative to the current time]'
- "--date=-[format of date output]:date format:((relative\:'show dates relative to the current time'
- local\:\"show timestamps in user's local timezone\"
- default\:'show timestamp in the original timezone\""
+ '--date=-[format of date output]:date format:((relative\:"show dates relative to the current time"
+ local\:"show timestamps in user'\''s local timezone"
+ default\:"show timestamp in the original timezone"))'
'--author=-[limit commits to those by the given author]:author'
'--committer=-[limit commits to those by the given committer]:committer'
'--grep=-[limit commits to those with log messages matching the given pattern]:pattern'
@@ -4109,6 +4109,28 @@
local curcontext=$curcontext ret=1
+ # fun with $words[] and $CURRENT to enable completion for args
+ # to git aliases (eg. git co <TAB>)
+ local -A git_aliases
+ # TODO: filling git_aliases like this is ugly. I didn't get it working elegantly.
+ local oifs=$IFS
+ IFS=$'\0'
+ git_aliases=(${=${(0)${(@)${${${(f)"$(git config --get-regexp alias.\*)"}/(#s)alias./}/ /$'\0'}}}})
+ IFS=$oifs ; unset oifs
+
+ if (( CURRENT >= 3 )) && [[ -n ${git_aliases[$words[2]]} ]] ; then
+ local -a tmpwords
+ tmpwords=(${words[1]} ${(z)git_aliases[$words[2]]})
+ if [[ -z "${words[3,-1]}" ]] ; then
+ tmpwords[$(( ${#tmpwords} + 1 ))]=""
+ else
+ tmpwords+=("${words[3,-1]}")
+ fi
+ words=("${tmpwords[@]}")
+ (( CURRENT += ${#${(z)git_aliases[$words[2]]}} - 1 ))
+ unset tmpwords
+ fi
+
if [[ $words[1] == git ]]; then
local state line
declare -A opt_args
Messages sorted by:
Reverse Date,
Date,
Thread,
Author