Search code examples
zshcompletion

ZSH Completion Delimiter


I ran into the following situation. I got autocomplete entries like those:

server:install
server:lint
...

Those should be completable by zsh. Actually my completion method works kind of nice, as long as I replace the colons by underscores or something different, as ZSH (or better the _describe function) will use colons as delimiter.

You can see this in this example:

local -a subcmds topics
subcmds=('c:description for c command' 'd:description for d command')
topics=('e:description for e help topic' 'f:description for f help topic')
_describe 'command' subcmds -- topics

However, that's not what I want. I actually want to have those colons in the autocomplete entries.

So my question is: Can I either escape the colon somehow so that ZSH will note that my colon is not a delimiter for a description or change the delimiter to something different than a colon?

Currently the completion looks like this:

#compdef mycmd

local -a completions
completions=$(complete_me 2>/dev/null)
result=$(echo "$completions" | sed "s/:/_/g") # This line should be removed
lines=("${(f)result}")
_describe 'command' lines

All of this stuff is more or less copied together from various sites. So probably I just missed quite a simple option - but I just cannot find it -.-.

Can someone help me with this?

Thanks, Matthias


Solution

  • Grml - it was an easy answer. _describe (as the name says) always expects a description. Replacing it by compadd just works:

    compadd $lines
    

    Maybe more people are as stupid as me :D - so I'll leave it here...