Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Help overriding a single flag’s completion action
- X-seq: zsh-users 30381
- From: Langbart <Langbart@xxxxxxxxxxxxxx>
- To: Eric Cook <llua@xxxxxxx>
- Cc: zsh-users@xxxxxxx
- Subject: Re: Help overriding a single flag’s completion action
- Date: Sat, 18 Oct 2025 14:50:39 +0000
- Archived-at: <https://zsh.org/users/30381>
- Feedback-id: 20607877:user:proton
- In-reply-to: <fc4833b7-6f2b-41d9-a191-d095b8bc5d2f@gmx.com>
- List-id: <zsh-users.zsh.org>
- References: <ODnvLTKj2DqepJxxzSagescOIp7mj6nuw1CgWQdDAm1fVFcfYrXChVGyYrcPEdbI9xYLwW2ggJs5gE8tp3KgZjNKKgupj2nkG1r3OVgGvug=@protonmail.com> <apgKsXxIZyI4ANVjhk-2WifBfQo46QNJ8tXsZrrllQHcta8A87xL-k_0EC1GpqjqPpFVm6V9d4xxQTo8BzlqrU7p1ClnatCxZc-6fMuw5J4=@protonmail.com> <fc4833b7-6f2b-41d9-a191-d095b8bc5d2f@gmx.com>
On Monday, October 13th, 2025 at 9:48 AM, Eric Cook <llua@xxxxxxx> wrote:
> On 10/13/25 1:34 AM, Langbart wrote:
>
> > > Could you advise on the correct approach?
> >
> > I tried zstyle first but never found the right syntax; using compdef with a helper function worked.
>
> zstyle :completion::complete:fabric:\:option--model-1 fake foo bar baz
>
> you type fabric --model and press ^xh to invoke _complete_help to get the `context' the completion system has
Thanks, the _complete_help/_complete_debug hotkey was a useful advice, to see
that the argument is called option--model-1 and not --model.
I was able to add fake values but not overwrite the original ones.
I believe this is because the original _fabric_models function doesn't process
any additional arguments passed to it.
After altering the original completion function
from: compadd -X "Models:" ${models}
to: compadd -X "Models:" "$@" ${models}
This change allowed me to use the following in .zshrc to show only my custom completions.
zstyle ':completion::complete:fabric*:*:option--model-1' fake-always foo bar
zstyle ':completion::complete:fabric*:*:option--model-1' ignored-patterns '*'
Alternatively, zstyle -e with a helper function worked as well, but I had to set
_comp_ignore=() to hide other values from the original call.
_fab_wrap() {
local -a _comp_ignore=()
local -a my_itmes=(
'alpha:100k'
'beta:20k'
'gamma:4k'
)
_describe '' my_itmes
}
zstyle -e ':completion::complete:fabric*:*:option--model-1' fake-always _fab_wrap
zstyle ':completion::complete:fabric*:*:option--model-1' ignored-patterns '*'
However, the original function (_fabric_models) still calls the vendor API to
fetch the models, causing a slight delay. As I can’t fully prevent that function
from running for this flag via zstyle, I’ll stick to the compdef workaround.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author