From: Mikael Magnusson <mikachu@gmail.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: zsh workers <zsh-workers@zsh.org>
Subject: Re: 'cd' completion for git-worktree(1) - how to '_wanted $tag' defaulting to false?
Date: Tue, 11 Sep 2018 01:21:46 +0200 [thread overview]
Message-ID: <CAHYJk3QFvetRh1ihQ+ehR6aiNVJ6O3dNYw3xqQTQpvi2LVh+vQ@mail.gmail.com> (raw)
In-Reply-To: <20180910164931.dkagh72zk5sefduf@tarpaulin.shahaf.local2>
On Mon, Sep 10, 2018 at 6:49 PM, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 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.
I would go with a separate function for this, like git-cd or
something. This would then also make the completer part trivial :).
Another option is to have another keybind than tab to offer git
worktrees (not just for cd). Or you can use the ~[] mechanism.
--
Mikael Magnusson
prev parent reply other threads:[~2018-09-10 23:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-10 16:49 Daniel Shahaf
2018-09-10 23:21 ` Mikael Magnusson [this message]
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=CAHYJk3QFvetRh1ihQ+ehR6aiNVJ6O3dNYw3xqQTQpvi2LVh+vQ@mail.gmail.com \
--to=mikachu@gmail.com \
--cc=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).