zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: yet another _git update
@ 2007-06-23 10:02 Frank Terbeck
  2007-06-23 13:09 ` Nikolai Weibull
  2007-06-23 21:41 ` Clint Adams
  0 siblings, 2 replies; 6+ messages in thread
From: Frank Terbeck @ 2007-06-23 10:02 UTC (permalink / raw)
  To: zsh workers

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: yet another _git update
  2007-06-23 10:02 PATCH: yet another _git update Frank Terbeck
@ 2007-06-23 13:09 ` Nikolai Weibull
  2007-06-23 21:55   ` Clint Adams
  2007-06-23 21:41 ` Clint Adams
  1 sibling, 1 reply; 6+ messages in thread
From: Nikolai Weibull @ 2007-06-23 13:09 UTC (permalink / raw)
  To: zsh workers

On 6/23/07, Frank Terbeck <ft@bewatermyfriend.org> wrote:
> 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.

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

Hi!

Works fine now.  These issues have been addressed, yes.  Commands are
broken up into different groups, so you can easily configure what gets
shown.

One way of making sure that commands that we currently don't know
about gets included is to merge the output of $(git help -a) with the
list of commands we have descriptions for.  That way you don't have to
choose.  Also, you can avoid the description if you don't want the
long list:

  zstyle ':completion::complete:git:*' verbose no

or something like that.

  nikolai


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: yet another _git update
  2007-06-23 10:02 PATCH: yet another _git update Frank Terbeck
  2007-06-23 13:09 ` Nikolai Weibull
@ 2007-06-23 21:41 ` Clint Adams
  2007-06-23 21:51   ` Frank Terbeck
  1 sibling, 1 reply; 6+ messages in thread
From: Clint Adams @ 2007-06-23 21:41 UTC (permalink / raw)
  To: zsh workers

On Sat, Jun 23, 2007 at 12:02:26PM +0200, Frank Terbeck wrote:
>   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.

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

What about putting the descriptions into an assoc array, and matching
those up with the output of git help -a instead?  Then you could have
the best of both potential style options by default.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: yet another _git update
  2007-06-23 21:41 ` Clint Adams
@ 2007-06-23 21:51   ` Frank Terbeck
  0 siblings, 0 replies; 6+ messages in thread
From: Frank Terbeck @ 2007-06-23 21:51 UTC (permalink / raw)
  To: zsh workers

Clint Adams <clint@zsh.org>:
> On Sat, Jun 23, 2007 at 12:02:26PM +0200, Frank Terbeck wrote:
> >   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.
> 
> > To activate a), do:
> >   zstyle ':completion::*:git:*' list_allcmds true
> 
> What about putting the descriptions into an assoc array, and matching
> those up with the output of git help -a instead?  Then you could have
> the best of both potential style options by default.

I would be all for it.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: yet another _git update
  2007-06-23 13:09 ` Nikolai Weibull
@ 2007-06-23 21:55   ` Clint Adams
  2007-06-24  8:54     ` Nikolai Weibull
  0 siblings, 1 reply; 6+ messages in thread
From: Clint Adams @ 2007-06-23 21:55 UTC (permalink / raw)
  To: Nikolai Weibull; +Cc: zsh workers

On Sat, Jun 23, 2007 at 03:09:29PM +0200, Nikolai Weibull wrote:
> Works fine now.  These issues have been addressed, yes.  Commands are
> broken up into different groups, so you can easily configure what gets
> shown.

Any reason you didn't use tags here instead of the style stuff?

 296 local wanted_commands
 297 zstyle -s ':completion:${curcontext}:' commands wanted_commands || wanted_commands="all -internal"
 298 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: yet another _git update
  2007-06-23 21:55   ` Clint Adams
@ 2007-06-24  8:54     ` Nikolai Weibull
  0 siblings, 0 replies; 6+ messages in thread
From: Nikolai Weibull @ 2007-06-24  8:54 UTC (permalink / raw)
  To: Nikolai Weibull, zsh workers

On 6/23/07, Clint Adams <clint@zsh.org> wrote:
> On Sat, Jun 23, 2007 at 03:09:29PM +0200, Nikolai Weibull wrote:
> > Works fine now.  These issues have been addressed, yes.  Commands are
> > broken up into different groups, so you can easily configure what gets
> > shown.
>
> Any reason you didn't use tags here instead of the style stuff?
>
>  296 local wanted_commands
>  297 zstyle -s ':completion:${curcontext}:' commands wanted_commands || wanted_commands="all -internal"

Hm, because I wasn't thinking, I guess.  I'll rework it.

Thanks for highlighting this,

  nikolai


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-06-24  8:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-23 10:02 PATCH: yet another _git update Frank Terbeck
2007-06-23 13:09 ` Nikolai Weibull
2007-06-23 21:55   ` Clint Adams
2007-06-24  8:54     ` Nikolai Weibull
2007-06-23 21:41 ` Clint Adams
2007-06-23 21:51   ` Frank Terbeck

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).