我正在为 zsh 编写一个自动完成脚本,我想在某些条件下启用 nospace。 bash 等效脚本如下所示
_my_completion(){
if something; then
compopt -o nospace
fi
}
complete -F _my_completion <exec>
如何在 zsh 中实现相同的目标?
最佳答案
使用 -S ''
可以实现类似的效果。如 compadd
论证,如你所见:
_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>
如果您熟悉 bash 补全,您可以在 this script that loads the bash completions in ZSH 中了解 zsh 补全的比较情况。 .
关于linux - zsh 中修改当前完成选项的 compopt 等效项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48000023/