Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Is there a way to complete arguments with brace characters without using backslashes or quotes?



Thanks, I have reduced my zsh configuration to a minimal setup, but I'm still getting the same results. Here is my /home/trevor/.zshrc

fpath=(/home/trevor/zsh_completions/ $fpath)
autoload -Uz compinit promptinit
compinit
promptinit

and here is /home/trevor/zsh_completions/_myfun

#compdef myfun
compadd -Q a{b
compadd -Q a{c

and then I enter

$ setopt ignore_braces
$ myfun <TAB>

which completes to

$ myfun a{

but then nothing happens on subsequent TAB presses (the two completion options aren't shown). If I change "a{b" and "a{c" to "abb" and "abc" then it works as expected (it shows the two options below prompt on the first TAB press, and then cycles through them on subsequent TAB presses). I am using Arch Linux and have tried a few different terminal emulators as well.


On Mon, Mar 24, 2025 at 12:40 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
On Mon, Mar 24, 2025 at 4:48 AM Trevor Avant <trevoravant@xxxxxxxxx> wrote:
>
> I've spent a lot of time trying to figure this out, but haven't been able to find a solution. Is there a way to complete the brace characters { or } without having to escape them with a backslash, or put the entire argument in quotes? In other words, I would like to make zsh treat the brace character as it does letter and number characters.
>
> I have tried using the "-Q" flag to compadd, but this doesn't work as I hoped. For example, I set the following for a function named "myfun":
>
> compadd -Q a{b
> compadd -Q a{c
>
> and then entering
>
> $ setopt ignore_braces
> $ myfun <TAB>
>
> will complete to
>
> $ myfun a{
>
> but the two completion options aren't shown.

Works fine here, so you'll probably have the same results if you
change your code to abb abc instead of a{b a{c. Eg, the problem is
something else. Try pressing tab more times, you can configure zsh to
require quite a few presses on ambiguous completion before it starts
cycling, and probably disable it altogether.

--
Mikael Magnusson


Messages sorted by: Reverse Date, Date, Thread, Author