Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: git --pretty completion, and (new) completion for npm



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