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

'cd' completion for git-worktree(1) - how to '_wanted $tag' defaulting to false?



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



Messages sorted by: Reverse Date, Date, Thread, Author