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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With