Re: Help overriding a single flag’s completion action
Langbart <[email protected]> Sat, 18 Oct 2025 14:50:39 +0000
| Newsgroups | gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user |
|---|---|
| Message-ID | <mdCXwS_HhGcUtgJlTUwhTJsGCwpE0iH0ablgkP5M2jD9hq_oHF9ZBsujm1G1C40saRm8U3m9tywLbpjk9tCfidGU5KQ40VdrIav63lWyaAM=@protonmail.com> |
On Monday, October 13th, 2025 at 9:48 AM, Eric Cook <[email protected]> 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.