Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: git --pretty completion, and (new) completion for npm
- X-seq: zsh-workers 28932
- From: Johan Sundström <oyasumi@xxxxxxxxx>
- To: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: PATCH: git --pretty completion, and (new) completion for npm
- Date: Sun, 20 Mar 2011 04:52:10 -0700
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=/1A59SlZF0fEb4Cn8HbzdJE3kjOmsRbFl2Iwk5vSmsU=; b=aPKvL4LWcZ8Idc1BSlOZhzARbl0847InFYWxQM43U4gmBrA5pF4DNiXjDLJ4k+9tDT 10uKEAETPoe6ztsijftZkyjRzG/xgpZ3BU4bJyu1x2wxGg8wRPN1Rzlq73FFKcEn1lZk sf14eMHI2Py8liHFBOLuxcDMKLzkK/KgAEWHk=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=H3PnDTzYAiSO3Smn7EfAHk5MxfEozDDWsGF8kGUoeUexINJNd9NgD4fl+PYXJbJscX F/CM3VcaY1TUax+ubgXl64chSK1/ocPp95w1FOc+FDOtWQMeyKNWbrNt9eFJx53D98dH gJE42cUlgxRe7Hun+2+yGRmrrEfF6UHN1wYOY=
- In-reply-to: <871v22krki.fsf@ft.bewatermyfriend.org>
- 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: <AANLkTi=Evf1nLVkKF9pr0t_hdzuTXJNi0nA6bcD9KBdT@mail.gmail.com> <871v22krki.fsf@ft.bewatermyfriend.org>
On Sun, Mar 20, 2011 at 03:35, Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx> wrote:
> Johan Sundström wrote:
> [...]
> > I took to adding documented completion for to the git completer for
> syntax that
> > is impossible to remember and hard to find in the man page; git log
> --pretty
> > (and whichever other commands support --pretty / --format) now covers the
> whole
> > lot except %w, which seemed like it would need a whole little state
> machine in
> > itself.
>
> Hm. This only works for stuff directly after the `=', doesn't it? As in:
>
> % git log -1 --pretty=%<tab>
>
Correct; enough to document what the properties are when there's just the
one you're interested in (for me it's usually %H for the commit hash), but
sub-ideal for longer formats.
But not in:
>
> % git log -1 --pretty="%H %<tab>
>
> That would be pretty useful, don't you think?
>
It certainly would, but I fear my completion beard is not quite long enough
yet for me to pull off that state machine, myself. :-)
If someone is up for that, it might also be worth adding the %w flag which
takes one or two numeric arguments while at it, with correct syntax looking
like either of these:
%w(integer_width)
%w(integer_width,integer_indent_first_line)
%w(integer_width,integer_indent_first_line,integer_indent_subsequent_lines)
Full documentation, as resolved after cross-referencing the right excerpts
of the right sections of "man git log" and "man git short-log" and testing
to verify that it's correct (and fixing the defaults, that turned out to be
different for git log):
%w(<width>[,<indent1>[,<indent2>]])
Linewrap the output by wrapping each line at width. The first line of each
entry is indented by indent1 spaces, and the second and subsequent lines are
indented by indent2 spaces. indent1, and indent2 both default to 0.
I'm not entirely sure how a good completion for %w would operate to convey
some of that, though. Not specified anywhere, but found by testing: the
wrapping applies to the %s and %b formats only (commit message subject and
body lines).
Also, you can cancel out the use of sed(1) from the code:
> diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
> index d65362e..ef4f263 100644
> --- a/Completion/Unix/Command/_git
> +++ b/Completion/Unix/Command/_git
> @@ -5550,8 +5550,7 @@ __git_setup_pretty_aliases () {
> aliases=()
> for spec in $(git config --get-regexp '^pretty\.' 2>/dev/null); do
> name="${${spec#pretty.}/ */}"
> - pfmt="${spec#pretty.$name }"
> - pfmt="$(sed 's_\([]:["]\)_\\\1_g' <<<"$pfmt")" # escapes ], :, [, and
> "
> + pfmt="${${spec#pretty.$name }//(#b)([]:[\"])/\\\\${match[1]}}"
> aliases+=(${name}'\:"git config alias for\: '${pfmt}'"')
> done
> pretty_aliases="${(pj:\n:)aliases}"
>
> ...which would save a fork().
>
Ah, that's what it looks like! I tried for a bit, but failed. For that
amount of magic, I'd say it's fair to keep the comment; what the line
accomplishes doesn't quite jump out at you, and if there's need of debugging
(or other changes) later, it's good to know the current/prior intent.
Regards, Frank
>
> PS: I've just committed the _npm completion from the message I'm
> replying to.
>
Thanks!
--
/ Johan Sundström, http://ecmanaut.blogspot.com/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author