Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Improved completion for git commit objects (__git_commit_objects)
- X-seq: zsh-workers 34640
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Daniel Hahler <genml+zsh-workers@xxxxxxxxxx>
- Subject: Re: Improved completion for git commit objects (__git_commit_objects)
- Date: Wed, 4 Mar 2015 02:57:20 +0000
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type :content-transfer-encoding:in-reply-to; s=mesmtp; bh=t4UHqgwFOkL Mu9qDpz0BYg4s+5Y=; b=Dh0MA0zWhgqMaV1xovEbcusAr3QhzsjYJ9xxnIuJtNa /5B5U2ZKpINSrOzMvJTVshItdIa38Saoy7SCb+kdoGzk7JFd4JuvMqsprDm6TSCd a4yHUSHrP09NkSqMYG9kG8c6ym6lCzIqcrwabLcgDPpUT5AHS9JLj/sFaGyoozvI =
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type :content-transfer-encoding:in-reply-to; s=smtpout; bh=t4UHqgwFOk LMu9qDpz0BYg4s+5Y=; b=lD/mkAR9PhUyy1bB322QhlQ6+UL4Y6pucgKTBeWYvj mqp1zJOyoDtdpjgCbWKwzhoq3B4ItHRhCBplgdOQupYd+CC2aZ2QS4M4ynF50MYt jAOoq6McaPUf3KE9uiDGzhZ+Qps0bptBgE1oTvAX2eq0iJwiM4cIWVyhAu1N3tMC E=
- In-reply-to: <20150304024000.GF2057@tarsus.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <54F647E2.5020400@thequod.de> <20150304024000.GF2057@tarsus.local2>
Daniel Shahaf wrote on Wed, Mar 04, 2015 at 02:40:00 +0000:
> Daniel Hahler wrote on Wed, Mar 04, 2015 at 00:46:42 +0100:
> > _guard '[[:xdigit:]](#c,40)' 'commit object name'
> > +
> > + : ${(AA)commits::=${(f)"$(_call_program commits git --no-pager log --oneline -2 --format='%h%n%s')"}}
> > + __git_command_successful $pipestatus || return 1
> > +
> > + _wanted commits expl 'commit object name' compadd "$@" -k - commits && ret=0
> > }
> >
> > I do not fully understand how "_guard" is meant to be used - I need to comment/remove it.
> > Should this get chained, e.g. with "_wanted", instead?
>
> What's the desired behaviour? Suppose that ${(k)commits} is [0123abc,
> 4567def] and the user types '--fixup=fedbca<TAB>'. In this case, you'd
> still want the second argument to _guard to be displayed, right?
>
> In this case, I think you should retain _guard in the "the 'commits' tag
> is wanted, but none of ${(k)commits} matches the input so far" codepath.
> Makes sense?
Never mind that — I think you can just remove the _guard call. The
function of _guard is to display a message when the current word matches
a pattern (sort of conditionalizing the second colon-separated part of
an _arguments option definition); _wanted will print that message
instead of _guard.
That confused me too the first time I encountered that function.
Perhaps a clarification:
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 5890f17..89cd051 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -4278,12 +4278,12 @@ option `tt(-)tt(-help)'.
)
findex(_guard)
item(tt(_guard) [ var(options) ] var(pattern descr))(
-This function is intended to be used in the var(action) for
-the specifications passed to tt(_arguments) and similar functions. It
-returns immediately with a non-zero return status if
-the string to be completed does not match the var(pattern). If the
-pattern matches, the var(descr) is displayed; the function then returns
-status zero if the word to complete is not empty, non-zero otherwise.
+This function displays var(descr) if var(pattern) matches the string to
+be completed. It is intended to be used in the var(action) for the
+specifications passed to tt(_arguments) and similar functions.
+
+The return status is zero if the message was displayed and the word to
+complete is not empty, and non-zero otherwise.
The var(pattern) may be preceded by any of the options understood by
tt(compadd) that are passed down from tt(_description), namely tt(-M),
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author