Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: yet another _git update



Hi list.

The following patch addresses the following issues:
(all related to _git_commands)

  a) To provide a nice looking list, we currently use a hardcoded list
     of 'command:description' pairs. However this does not guarantee,
     that all possible subcommands available on a system will be taken
     into account.

  b) git has got a nice feature, that lets you define aliases for
     commonly used commands, so that you can do 'git pub', which git
     may then (if configured) expand to 'git push public', to push
     local changes to a public repository for example. (Of course,
     you need to configure git, so that it knows where 'public' is.)
     These aliases are currently not considered.

Both of these features are optional.

To activate a), do:
  zstyle ':completion::*:git:*' list_allcmds true

To activate b), do:
  zstyle ':completion::*:git:*' list_aliases true

By accident, this patch also solves the 'TODO' comment above the
'_git_commands' function:

[snip]
 # TODO: either skip uninteresting commands or skip the description -
 # the list is just too long
[snap]

...because a) effectively skips the description, as the 'git help -a'
command does not (yet?) provide such information.

If you prefer the more verbose hardcoded listing, and think that the
comment is still right, because you should better be able to skip
uninteresting commands, you may use the ignored-patterns style, to
weed out things you don't want.

For example, if you'd like the completion to skip subcommands starting
with 'diff-' and 'merge-' (while keeping 'merge' and 'diff'), do:

  zstyle ':completion::*:git:*' ignored-patterns '(diff|merge)-*'

As far as I am concerned, that gives me all the possibilities I would
want (for now) from the '_git_commands' part of '_git'.

  (Nikolai: I wanted to check your _git-repo this morning, to see, if
   you addressed this one already. However I got an 'Access denied.'.)

Regards, Frank


Index: Completion/Unix/Command/_git
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_git,v
retrieving revision 1.4
diff -u -r1.4 _git
--- Completion/Unix/Command/_git	14 Jun 2007 14:42:37 -0000	1.4
+++ Completion/Unix/Command/_git	23 Jun 2007 09:58:27 -0000
@@ -74,110 +74,117 @@
 
 tags_fetch_arg=('(-t --tags)'{-t,--tags}'[fetch remote tags]')
 
-# TODO: either skip uninteresting commands or skip the description - the list
-# is just too long
 _git_commands () {
-  local -a commands
+  local -a commands aliases
 
-  commands=(
-    'add:add paths to the index'
-    'am:apply patches from a mailbox (cooler than applymbox)'
-    'apply:apply patch on a git index file and a work tree'
-    'applymbox:apply patches from a mailbox'
-    'applypatch:apply one patch extracted from an e-mail'
-    'archimport:import an Arch repository into git'
-    'bisect:find the change that introduced a bug'
-    'branch:create and show branches'
-    'cat-file:provide content or type information for repository objects'
-    'check-ref-format:makes sure that a reference-name is well formed'
-    'checkout:checkout and switch to a branch'
-    'checkout-index:copy files from the index to the working directory'
-    'cherry:find commits not merged upstream'
-    'cherry-pick:cherry-pick the effect of an existing commit'
-    'clone:clones a repository into a new directory'
-    'clone-pack:clones a repository into the current repository (transport)'
-    'commit:record changes to the repository'
-    'commit-tree:creates a new commit object'
-    'convert-objects:converts old-style git repository'
-    'count-objects:count unpacked objects and display their disk consumption'
-    'cvsimport:import a CVS "repository" into a git repository'
-    'daemon:starts a really simple server for git repositories'
-    'diff:show changes between commits, commit and working tree, etc.'
-    'diff-files:compares files in the working tree and the index'
-    'diff-index:compares content and mode of blobs between index and repository'
-    'diff-stages:compares two "merge states" in the index file'
-    'diff-tree:compares the content and mode of blobs found via two tree objects'
-    'fetch:download objects and a head from another repository'
-    'fetch-pack:receive missing objects from another repository'
-    'format-patch:prepare patches for e-mail submission'
-    'fsck-objects:verifies the connectivity and validity of the objects in the database'
-    'get-tar-commit-id:extract commit ID from an archive created using tar-tree'
-    'grep:print lines matching a pattern'
-    'hash-object:computes the object ID from a file'
-    'http-fetch:downloads a remote git repository via HTTP'
-    'index-pack:build pack index file for an existing packed archive'
-    'init-db:creates an empty git object database'
-    'local-fetch:duplicates another git repository on a local system'
-    'log:shows commit logs'
-    'lost-found:recovers lost references that luckily have not yet been pruned'
-    'ls-files:information about files in the index/working directory'
-    'ls-remote:shows references in a remote or local repository'
-    'ls-tree:displays a tree object in human-readable form'
-    'mailinfo:extracts patch from a single e-mail message'
-    'mailsplit:splits an mbox file into a list of files'
-    'merge:grand unified merge driver'
-    'merge-base:finds a good common ancestor as possible for a merge'
-    'merge-index:runs a merge for files needing merging'
-    'merge-one-file:standard helper-program to use with merge-index'
-    'mktag:creates a tag object'
-    'mv:moves or renames a file, directory, or symlink'
-    'name-rev:find symbolic names for given revisions'
-    'octopus:merges more than two commits'
-    'pack-objects:creates a packed archive of objects'
-    'parse-remote:routines to help parsing $GIT_DIR/remotes/'
-    'patch-id:computes unique ID for a apatch'
-    'peek-remote:lists references on a remote repository using the upload-pack protocol'
-    'prune:prunes all unreachable objects from the object database'
-    'prune-packed:removes extra objects that are already in pack files'
-    'pull:fetch from and merge with a remote repository'
-    'push:update remote refs along with associated objects'
-    'read-tree:reads tree information into the directory index'
-    'rebase:rebases local commits to new upstream head'
-    'receive-pack:command invoked by send-pack to receive what is pushed to it'
-    'relink:hardlinks acommon objects in local repositories'
-    'repack:packs unpacked objects in a repository'
-    'request-pull:generates a summary of pending changes'
-    'reset:resets current HEAD to the specified state'
-    'resolve:merges two commits'
-    'rev-list:lists commit object in reverse chronological order'
-    'rev-parse:picks out and massages parameters for other git commands'
-    'revert:reverts an existing commit'
-    'send-email:sends patch-e-mails out of "format-patch --mbox" output'
-    'send-pack:pushes to a remote repository, intelligently'
-    'shortlog:summarizes git log output'
-    'show-branch:shows branches and their commits'
-    'show-index:displays contents of a pack idx file'
-    'ssh-fetch:pulls from a remote repository over an SSH connection'
-    'ssh-upload:helper "server-side" program used by ssh-fetch'
-    "status:shows the working-tree's status"
-    'stripspace:filters out empty lines'
-    'svnimport:imports a SVN repository into git'
-    'symbolic-ref:reads and modifies symbolic references'
-    'tag:creates a tag object signed with GPG'
-    'tar-tree:creates a tar archive of the files in the named tree'
-    "unpack-file:creates a temporary file with a blob's contents"
-    'unpack-objects:unpacks objects out of a packed archive'
-    'update-index:modifies the index in some given way'
-    'update-ref:updates the object name stored in a reference safely'
-    'update-server-info:updates auxiliary information on a dumb server'
-    'upload-pack:command invoked by clone-pack and fetch-pack'
-    'var:displays a git logical variable'
-    'verify-pack:validates packed git archive files'
-    'verify-tag:checks the GPG signature of a tag'
-    'whatchanged:shows commit-logs and differences they introduce'
-    'write-tree:creates a tree from the current index')
+  if zstyle -t ":completion:${curcontext}:" list_allcmds ; then
+    commands=(${(s: :)${(M)${(f)"$(git help -a)"}:# ##*}})
+  else
+    commands=(
+      'add:add paths to the index'
+      'am:apply patches from a mailbox (cooler than applymbox)'
+      'apply:apply patch on a git index file and a work tree'
+      'applymbox:apply patches from a mailbox'
+      'applypatch:apply one patch extracted from an e-mail'
+      'archimport:import an Arch repository into git'
+      'bisect:find the change that introduced a bug'
+      'branch:create and show branches'
+      'cat-file:provide content or type information for repository objects'
+      'check-ref-format:makes sure that a reference-name is well formed'
+      'checkout:checkout and switch to a branch'
+      'checkout-index:copy files from the index to the working directory'
+      'cherry:find commits not merged upstream'
+      'cherry-pick:cherry-pick the effect of an existing commit'
+      'clone:clones a repository into a new directory'
+      'clone-pack:clones a repository into the current repository (transport)'
+      'commit:record changes to the repository'
+      'commit-tree:creates a new commit object'
+      'convert-objects:converts old-style git repository'
+      'count-objects:count unpacked objects and display their disk consumption'
+      'cvsimport:import a CVS "repository" into a git repository'
+      'daemon:starts a really simple server for git repositories'
+      'diff:show changes between commits, commit and working tree, etc.'
+      'diff-files:compares files in the working tree and the index'
+      'diff-index:compares content and mode of blobs between index and repository'
+      'diff-stages:compares two "merge states" in the index file'
+      'diff-tree:compares the content and mode of blobs found via two tree objects'
+      'fetch:download objects and a head from another repository'
+      'fetch-pack:receive missing objects from another repository'
+      'format-patch:prepare patches for e-mail submission'
+      'fsck-objects:verifies the connectivity and validity of the objects in the database'
+      'get-tar-commit-id:extract commit ID from an archive created using tar-tree'
+      'grep:print lines matching a pattern'
+      'hash-object:computes the object ID from a file'
+      'http-fetch:downloads a remote git repository via HTTP'
+      'index-pack:build pack index file for an existing packed archive'
+      'init-db:creates an empty git object database'
+      'local-fetch:duplicates another git repository on a local system'
+      'log:shows commit logs'
+      'lost-found:recovers lost references that luckily have not yet been pruned'
+      'ls-files:information about files in the index/working directory'
+      'ls-remote:shows references in a remote or local repository'
+      'ls-tree:displays a tree object in human-readable form'
+      'mailinfo:extracts patch from a single e-mail message'
+      'mailsplit:splits an mbox file into a list of files'
+      'merge:grand unified merge driver'
+      'merge-base:finds a good common ancestor as possible for a merge'
+      'merge-index:runs a merge for files needing merging'
+      'merge-one-file:standard helper-program to use with merge-index'
+      'mktag:creates a tag object'
+      'mv:moves or renames a file, directory, or symlink'
+      'name-rev:find symbolic names for given revisions'
+      'octopus:merges more than two commits'
+      'pack-objects:creates a packed archive of objects'
+      'parse-remote:routines to help parsing $GIT_DIR/remotes/'
+      'patch-id:computes unique ID for a apatch'
+      'peek-remote:lists references on a remote repository using the upload-pack protocol'
+      'prune:prunes all unreachable objects from the object database'
+      'prune-packed:removes extra objects that are already in pack files'
+      'pull:fetch from and merge with a remote repository'
+      'push:update remote refs along with associated objects'
+      'read-tree:reads tree information into the directory index'
+      'rebase:rebases local commits to new upstream head'
+      'receive-pack:command invoked by send-pack to receive what is pushed to it'
+      'relink:hardlinks acommon objects in local repositories'
+      'repack:packs unpacked objects in a repository'
+      'request-pull:generates a summary of pending changes'
+      'reset:resets current HEAD to the specified state'
+      'resolve:merges two commits'
+      'rev-list:lists commit object in reverse chronological order'
+      'rev-parse:picks out and massages parameters for other git commands'
+      'revert:reverts an existing commit'
+      'send-email:sends patch-e-mails out of "format-patch --mbox" output'
+      'send-pack:pushes to a remote repository, intelligently'
+      'shortlog:summarizes git log output'
+      'show-branch:shows branches and their commits'
+      'show-index:displays contents of a pack idx file'
+      'ssh-fetch:pulls from a remote repository over an SSH connection'
+      'ssh-upload:helper "server-side" program used by ssh-fetch'
+      "status:shows the working-tree's status"
+      'stripspace:filters out empty lines'
+      'svnimport:imports a SVN repository into git'
+      'symbolic-ref:reads and modifies symbolic references'
+      'tag:creates a tag object signed with GPG'
+      'tar-tree:creates a tar archive of the files in the named tree'
+      "unpack-file:creates a temporary file with a blob's contents"
+      'unpack-objects:unpacks objects out of a packed archive'
+      'update-index:modifies the index in some given way'
+      'update-ref:updates the object name stored in a reference safely'
+      'update-server-info:updates auxiliary information on a dumb server'
+      'upload-pack:command invoked by clone-pack and fetch-pack'
+      'var:displays a git logical variable'
+      'verify-pack:validates packed git archive files'
+      'verify-tag:checks the GPG signature of a tag'
+      'whatchanged:shows commit-logs and differences they introduce'
+      'write-tree:creates a tree from the current index'
+    )
+  fi
 
   _describe -t commands 'git command' commands && ret=0
+  if zstyle -t ":completion:${curcontext}:" list_aliases ; then
+    aliases=(${${${(f)"$(git-config --get-regexp 'alias\..*')"}/(#s)alias./}/ ##/:})
+    _describe -t aliases 'git command alias' aliases && ret=0
+  fi
 }
 
 # TODO: this needs to be cleaned up and fixed



Messages sorted by: Reverse Date, Date, Thread, Author