zsh-workers
 help / color / mirror / code / Atom feed
From: "Johan Sundström" <oyasumi@gmail.com>
To: Frank Terbeck <ft@bewatermyfriend.org>
Cc: zsh-workers@zsh.org
Subject: Re: PATCH: git --pretty completion, and (new) completion for npm
Date: Sun, 20 Mar 2011 04:52:10 -0700	[thread overview]
Message-ID: <AANLkTikdnYQWz=kKeiasBE7wG+rO2=+HSKQet53BkQK1@mail.gmail.com> (raw)
In-Reply-To: <871v22krki.fsf@ft.bewatermyfriend.org>

[-- Attachment #1: Type: text/plain, Size: 3363 bytes --]

On Sun, Mar 20, 2011 at 03:35, Frank Terbeck <ft@bewatermyfriend.org> 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/

  reply	other threads:[~2011-03-20 11:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-14  6:38 Johan Sundström
2011-03-20 10:35 ` Frank Terbeck
2011-03-20 11:52   ` Johan Sundström [this message]
2011-08-03 14:46     ` Nikolai Weibull
2011-08-03 15:05       ` Mikael Magnusson
2011-08-03 15:21         ` Nikolai Weibull

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='AANLkTikdnYQWz=kKeiasBE7wG+rO2=+HSKQet53BkQK1@mail.gmail.com' \
    --to=oyasumi@gmail.com \
    --cc=ft@bewatermyfriend.org \
    --cc=zsh-workers@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).