All of lore.kernel.org
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: git@vger.kernel.org, Jonathan Nieder <jrnieder@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Thomas Rast <trast@student.ethz.ch>
Subject: Re: [PATCH v3] completion: add new _GIT_complete helper
Date: Mon, 7 May 2012 01:32:35 +0200	[thread overview]
Message-ID: <20120506233235.GN2164@goldbirke> (raw)
In-Reply-To: <CAMP44s3xwgsfjZA6r+bydu-5r1nEO5cGc=wcDSr+WdwunTtpwg@mail.gmail.com>

Hi,


On Sun, May 06, 2012 at 10:37:06PM +0200, Felipe Contreras wrote:
> On Sun, May 6, 2012 at 1:14 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:
> > On Sat, May 05, 2012 at 05:23:20PM +0200, Felipe Contreras wrote:
> >> This simplifies the completions, and makes it easier to define aliases:
> >>
> >>  _GIT_complete gf git_fetch
> >
> > So, 'gf' is an alias for 'git fetch', for which the user would like to
> > use the completion for 'git fetch', right?  But that completion
> > function is caled _git_fetch(), so the underscore prefix is missing
> > here.
> 
> No, it's not missing:
> 
>        local name="${2-$1}"
>        eval "$(typeset -f __git_func_wrap | sed -e "s/__git_func/_$name/")"
>        complete -o bashdefault -o default -o nospace -F _${name}_wrap
> $1 2>/dev/null \
>                || complete -o default -o nospace -F _${name}_wrap $1
> 
> See how we add '_' before $name?

Indeed, the '_' is added before $name no less than three times.  How
could I have missed that?! ;)  It would be better to do it once and be
done with it.

> There's not point in burdening the
> user with adding a prefix that will _always_ be there anyway.

I don't think it's that much of a burden.  The function is called
_git_fetch, use that as second argument

> > Besides, this example won't work, because the completion for 'git
> > fetch' uses __git_complete_remote_or_refspec(), which in turn relies
> > on finding out the name of the git command from the word on the
> > command line, and it won't be able to do that from 'gf'.
> 
> That's irrelevant, it's an example; 

It's relevant; if you give an example, then at least that example
should work properly, don't you think?

> replace with another command that
> doesn't use 'words', and it would work.

That it doesn't work has nothing to do with $words.  The problem is that
__git_complete_remote_or_refspec() expects to find the git command in
${words[1]}, but in case of an alias it can't.

> > I remember we discussed this in an earlier round, and you even
> > suggested a possible fix (passing the command name as argument to
> > __git_complete_remote_or_refspec()).  I think that's the right thing
> > to do here.
> 
> Yeah, but I suggested that in order to avoid the eval and the typeset
> that I require for future future patches, but it turns out it's still
> needed anyway, so my suggestion is to have a 'cmd' variable that
> stores the command; __git_func_wrap would take the responsibility of
> doing that.

Well, now I suggest to do that to fix
__git_complete_remote_or_refspec(), because that seems to be the
easiest, cleanest, and fastest solution.

> >> +     __git_func "$@"
> >
> > What is this "$@" for and why?  None of the _git_<cmd>() functions
> > take any arguments, nor does _git() and _gitk(), and AFAICT Bash won't
> > pass any either.
> 
> bash's complete passes 3 arguments.

Oh, indeed; the first argument is the command name, the second is the
current word, and the third is the previous word.  All these are
available in our completion functions as ${words[0]}, $cur, and $prev,
respectively.

> They might not be used, but it
> doesn't hurt to pass them either.

They _are_ not used, so passing them has no benefit either.  I would
rather stick to using $cur and $prev than $2 and $3.


Best,
Gábor

  reply	other threads:[~2012-05-06 23:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-05 15:23 [PATCH v3] completion: add new _GIT_complete helper Felipe Contreras
2012-05-05 15:54 ` Jonathan Nieder
2012-05-05 16:38   ` Felipe Contreras
2012-05-05 16:47     ` Jonathan Nieder
2012-05-05 16:52       ` Jonathan Nieder
2012-05-05 17:20       ` Felipe Contreras
2012-05-05 17:33         ` Jonathan gives feedback --> flamewars inevitable? (Re: [PATCH v3] completion: add new _GIT_complete helper) Jonathan Nieder
2012-05-05 18:23           ` Felipe Contreras
2012-05-05 18:39             ` Jonathan gives feedback --> flamewars inevitable? Jonathan Nieder
2012-05-05 18:42             ` Jonathan Nieder
2012-05-06  5:23           ` Jonathan gives feedback --> flamewars inevitable? (Re: [PATCH v3] completion: add new _GIT_complete helper) Tay Ray Chuan
2012-05-14  9:11             ` Felipe Contreras
2012-05-05 17:44         ` [PATCH v3] completion: add new _GIT_complete helper Jonathan Nieder
2012-05-06 10:30   ` SZEDER Gábor
2012-05-06 20:47     ` Jonathan Nieder
2012-05-06 11:14 ` SZEDER Gábor
2012-05-06 11:30   ` SZEDER Gábor
2012-05-06 11:36     ` SZEDER Gábor
2012-05-06 12:12   ` SZEDER Gábor
2012-05-06 20:53     ` Felipe Contreras
2012-05-06 20:37   ` Felipe Contreras
2012-05-06 23:32     ` SZEDER Gábor [this message]
2012-05-07  0:20       ` Felipe Contreras
2012-05-07  9:22         ` SZEDER Gábor

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=20120506233235.GN2164@goldbirke \
    --to=szeder@ira.uka.de \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=trast@student.ethz.ch \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.