zsh-workers
 help / color / mirror / code / Atom feed
* 'cd' completion for git-worktree(1) - how to '_wanted $tag' defaulting to false?
@ 2018-09-10 16:49 Daniel Shahaf
  2018-09-10 23:21 ` Mikael Magnusson
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2018-09-10 16:49 UTC (permalink / raw)
  To: zsh-workers

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-10 23:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-10 16:49 'cd' completion for git-worktree(1) - how to '_wanted $tag' defaulting to false? Daniel Shahaf
2018-09-10 23:21 ` Mikael Magnusson

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).