zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: 'cd' completion for git-worktree(1) - how to '_wanted $tag' defaulting to false?
Date: Mon, 10 Sep 2018 16:49:31 +0000	[thread overview]
Message-ID: <20180910164931.dkagh72zk5sefduf@tarpaulin.shahaf.local2> (raw)

Is it possible for «cd <TAB>» to offer git worktrees, when cwd is a git repo?

Completing git worktrees is easy:
.
        # excerpted from _git
        _wanted directories expl 'working tree' compadd -S ' ' -f -M 'r:|/=* r:|=*' \
            ${${(M)${(f)"$(_call_program directories git worktree list --porcelain)"}:#worktree*}#* } && ret=0
	.
	# independent reimplementation
	__git_worktree_directories() {
	  local -a expl targets=( ${${(f)"$(git worktree list)"}%% *} ) descs=( ${(f)"$(git worktree list)"} );
	  _wanted git-worktree-directories expl 'git worktree directories' compadd -ld descs -a targets
	}

I'm not sure how to hook that into _cd, though.  Checking whether we're
inside a git repository requires disk accesses and/or exec'ing
git-rev-parse(1), either of which may be expensive.  I suppose this
needs to be opt-in behaviour then, but I'm not sure how to ask "Did the
user opt-in to tag $foo?"; _requested assumes all tags are wanted except
those the user has explicitly opted out of.

Thoughts?

Cheers,

Daniel

             reply	other threads:[~2018-09-10 16:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-10 16:49 Daniel Shahaf [this message]
2018-09-10 23:21 ` Mikael Magnusson

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=20180910164931.dkagh72zk5sefduf@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).