From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16874 invoked by alias); 20 Mar 2011 11:52:20 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28932 Received: (qmail 28218 invoked from network); 20 Mar 2011 11:52:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.214.171 as permitted sender) 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= MIME-Version: 1.0 In-Reply-To: <871v22krki.fsf@ft.bewatermyfriend.org> References: <871v22krki.fsf@ft.bewatermyfriend.org> Date: Sun, 20 Mar 2011 04:52:10 -0700 Message-ID: Subject: Re: PATCH: git --pretty completion, and (new) completion for npm From: =?ISO-8859-1?Q?Johan_Sundstr=F6m?= To: Frank Terbeck Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary=90e6ba2121db2b9829049ee8a47d --90e6ba2121db2b9829049ee8a47d Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sun, Mar 20, 2011 at 03:35, Frank Terbeck wrote= : > Johan Sundstr=F6m 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 t= he > 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 `=3D', doesn't it? As in= : > > % git log -1 --pretty=3D% > 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=3D"%H % > > 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_line= s) 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([,[,]]) 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 ar= e 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=3D() > for spec in $(git config --get-regexp '^pretty\.' 2>/dev/null); do > name=3D"${${spec#pretty.}/ */}" > - pfmt=3D"${spec#pretty.$name }" > - pfmt=3D"$(sed 's_\([]:["]\)_\\\1_g' <<<"$pfmt")" # escapes ], :, [, = and > " > + pfmt=3D"${${spec#pretty.$name }//(#b)([]:[\"])/\\\\${match[1]}}" > aliases+=3D(${name}'\:"git config alias for\: '${pfmt}'"') > done > pretty_aliases=3D"${(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 debuggin= g (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! --=20 / Johan Sundstr=F6m, http://ecmanaut.blogspot.com/ --90e6ba2121db2b9829049ee8a47d--