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?
- X-seq: zsh-workers 43431
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: 'cd' completion for git-worktree(1) - how to '_wanted $tag' defaulting to false?
- Date: Mon, 10 Sep 2018 16:49:31 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=17dH4LdV/lFjidmLYINRTX8Szt0XO Ni+zsF4S90Z1OM=; b=bxJUgCYmOzbe9jS04emcoF2LgxEzuW/CIJIBJ3zziAPML vPdpUSeH0BfqzmsNGOfSAOfxYMkVibFG48MEXigJMB6kYJOuqe4nv1Zw4jVEQtcx 9UStz5+F2mHVSZKJI4iKLi4VarXwm5FiWzJ3+gUrWdE6gzp/gCyKK7xQ1P8oAxRe b/RYRQ9ExxZGSBjareWaKZreBSHaLZC4Ns6Hr2lQz+vAZo3MH/sHZtPs5PzIyTE3 wh2MpOJd2DpU+sx/arWBtc1haK2P1Wlgsydnh16+31tF/BVUeyxa2FtBol9tVxnB ZBQ0DMMzDZRCapxrf+r2s3X8zIenlr+IfQGYwQezQ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=17dH4LdV/lFjidmLYINRTX8Szt0XO Ni+zsF4S90Z1OM=; b=lfTxm/qz8IA37VcJq2BhVXDddpIxyoarg3JZYr1GCLozT WV1QR22mo6S0+NfPUQEueJr/T/LZn5heyRs6CNBQFNIUBvuwAq24CoYuyUnROAjq 7uDUf/5pgJjUlC4eMdqQ7677mrXVWhin1Z0oz4PTqUiMVG+g/BOAKONSxyIB/X5k 3Rh2wrUGbLlrAfnAhBuyb0Ncz0hUzx2RxY2xJwfY4QVU2fUcSScNKjKt5ZPUyHPd JvXPg9G7Jlr1bKHH3os9qSk+Pv6cByECsuUnxWKVS/PYh/uCm4Fl56qpfTpZXsdN PO06PNfpmz/1UTeoUlcClqgrmZ8oAJwBEZRagcLjQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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