From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh-users@zsh.org
Subject: Re: _git Completion and custom commands
Date: Tue, 28 Sep 2010 10:03:40 +0200 [thread overview]
Message-ID: <20100928080340.GJ9720@fsst.voodoo.lan> (raw)
In-Reply-To: <alpine.LNX.2.01.1009272342180.30023@hp>
Benjamin R. Haskell <zsh@benizi.com>:
[...]
>> The one issue I've found is that the _git completion function (as of
>> 4.3.10 shipped with Debian testing) does not include custom commands
>> (though it does include aliases).
[...]
> zstyle ':completion:*:git:*' user-commands ${${(k)commands[(I)git-*]}#git-}
Yes, this is explained at the top of the _git completion file.
Here's a little more:
The basic idea is that you can list your own git commands in the
`user-commands' style. And generally you're allowed to provide a
description for each command, too. So, say you've got a program
`git-foo', you can do this:
% zstyle ':completion:*:*:git:*' user-commands \
foo:'solves the question about the universe'
Now completing `git fo<tab>' results in a menu such as this (depending
on how compsys is configured, of course):
% % git fo<tab>
- git command -
foo -- solves the question about the universe
for-each-ref -- output information on each ref
format-patch -- prepare patches for e-mail submission
Now, if you want smartness, when you try `git foo <tab>' you may
write a function `_git-foo()' and _git will pick it up. So, if
your `git-foo' program supports a few options (-f, -v and -q), a
completion function may look like this:
function _git-foo() {
_arguments \
'-f[force stuff]' \
'-v[be verbose]' \
'-q[be quiet]' && ret=0;
}
With this, typing `git foo -<tab>' results in this menu:
% git foo -<tab>
- option -
-f -- force stuff
-q -- be quiet
-v -- be verbose
This can become as complicated as you like. :)
The `style' line Benjamin gave sets the `user-commands' style to a
list of all `git-*' commands zsh finds in $PATH. It's useful if you
got a *lot* of own scripts. Since zsh cannot guess a description for
the programs this way, commands added like that will be missing
descriptions.
Regards, Frank
PS: If the OP didn't configure compsys yet, then
<http://zshwiki.org/home/examples/compquickstart> may serve him
as a quickstart. I'll certainly help to get menus such as the
ones I mentioned above.
next prev parent reply other threads:[~2010-09-28 17:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-28 0:29 Conrad Irwin
2010-09-28 4:06 ` Benjamin R. Haskell
2010-09-28 5:28 ` Sebastian Stark
2010-09-28 6:30 ` Benjamin R. Haskell
2010-09-28 8:03 ` Frank Terbeck [this message]
2010-09-28 18:01 ` Conrad Irwin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100928080340.GJ9720@fsst.voodoo.lan \
--to=ft@bewatermyfriend.org \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).