Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: 'cd' completion for git-worktree(1) - how to '_wanted $tag' defaulting to false?
- X-seq: zsh-workers 43440
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Subject: Re: 'cd' completion for git-worktree(1) - how to '_wanted $tag' defaulting to false?
- Date: Tue, 11 Sep 2018 01:21:46 +0200
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=66qCsPFjFjVj8w1j+2jgRkwS5ME6NUzGcigahALyHQM=; b=YsZ+ZLkeCcuZJRJNEOn5fXijLVcudGQornK+5jw1IgPU9xzmVXFhze5oNa0w63zc3B 6CHhatX3CmP24AXSdxoHOYtJB/HwbKxKk9PP4rRMjtLla97YG/WOwUIjJy1gTPJqVI3I VZi3KV6hPGcdFiYqllqF32VrlFFhHz0a+kGDtvgHXssc8hyzEPYwsPAZz4sjQOdn5ccA s0gsS+AA8oEpPOye4A1Nao6MwFw+NxuHO5TQ5mBaIv7SV2yiP1prX3cy51N//xjJ/LnH K6lCzzLzH/M1aI1HKChVcgGWTBHElqD0W9trfqIsHZAoC5a0DOnUs4Q5BL3UA/jpn50e izyg==
- In-reply-to: <20180910164931.dkagh72zk5sefduf@tarpaulin.shahaf.local2>
- 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
- References: <20180910164931.dkagh72zk5sefduf@tarpaulin.shahaf.local2>
On Mon, Sep 10, 2018 at 6:49 PM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author