zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: git worktree add /foo <TAB>
Date: Wed, 16 Aug 2017 04:26:17 +0000	[thread overview]
Message-ID: <20170816042617.lud425bn2ycahy5d@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <15766.1502711853@thecus.kiddle.eu>

Oliver Kiddle wrote on Mon, Aug 14, 2017 at 13:57:33 +0200:
> On 9 Aug, Daniel Shahaf wrote:
> > The second argument to 'git worktree add' can be any committish.  That
> > committish becomes HEAD of the new worktree, and if it's a branch name,
> > then that branch becomes the current branch of the new worktree, else
> > the new worktree starts as a detached HEAD.
> >
> > How should that be completed?
> >
> > Currently it's completed as follows:
> >
> > +++ b/Completion/Unix/Command/_git
> > @@ -2026,11 +2026,7 @@ _git-worktree() {
> >        curcontext=${curcontext%:*}-$line[1]:
> >        case $line[1] in
> >          (add)
> >  	  if (( $words[(I)--detach] )); then
> >  	    args=( ':commit:__git_commits' )
> >  	  else
> >  	    args=( ':branch:__git_branch_names' )
> >  	  fi
> 
> I can't remember why it was done this way but I'm wondering if the
> two halves of the if…else…fi are the opposite way around from the
> intention. Specifying --detach would be superfluous for anything but
> a branch because it is the default for any other committish so after
> --detach there is sense in only completing branches.

+1

> I often apply logic such as this but it might not always be helpful,
> such as if --detach comes from an alias.

I don't understand.  Firstly, both zsh aliases and git aliases are
'seen through' in completion; secondly, the perfect shouldn't be the
enemy of the good.

> Otherwise, as you say, any committish is valid and our usual approach
> is to just complete them all and expect user's to set tag-order to give
> preference to the matches they find most useful. I suggested years back
> that we perhaps add a mechanism for giving a default tag-order and
> perhaps should consider it again.

Let's collect a few such settings before we invent a mechanism; it's
easier to invent when there are concrete details to work with.

To start with, here's one style I use:

    # Prefer recent commit object name completion
    zstyle ':completion::complete:git-(format-patch|send-email):argument-1:' group-order commits

> > I see __git_recent_branches but it's not precisely what I have in mind.
> 
> What would be useful in this case?

Just __git_branch_names — namely, names of local branches — is exactly
what I was after.  (Don't know how I managed to miss it)

So, yes, reversing the if and adding a tag-order/group-order style
should suffice.

Additionally, it would be nice if the group description said
"(alternatively specify name of new branch)" like _mkdir does.

Thanks,

Daniel


  reply	other threads:[~2017-08-16  4:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-09 19:31 Daniel Shahaf
2017-08-14 11:57 ` Oliver Kiddle
2017-08-16  4:26   ` Daniel Shahaf [this message]
2017-08-16  9:37     ` Oliver Kiddle

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=20170816042617.lud425bn2ycahy5d@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --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).