Reputation: 51
I am writing an auto completion script for zsh that I want to enable nospace on certain conditions. The bash equivalent script would look like this
_my_completion(){
if something; then
compopt -o nospace
fi
}
complete -F _my_completion <exec>
How do I achieve the same goal in zsh?
Upvotes: 5
Views: 603
Reputation: 3528
The similar effect can be done using -S ''
as compadd
argument, as you can see:
_my_completion(){
# Here you can access ${words[@]}, $BUFFER, $CURSOR, $NAME, $CURRENT...
if something; then
completions_array=(foo bar baz)
# `-S ''` is the equivalent of `compopt -o nospace`
compadd -S '' -a completions_array
fi
}
compdef _my_completion <exec>
If you're familiar with bash completions, you can see how zsh completions compare in this script that loads the bash completions in ZSH.
Upvotes: 2