Fix zsh completion scripts

This fix completion when argument startswith -
And prevent completing a space when no candidates
This commit is contained in:
Shengjing Zhu 2020-02-10 01:27:45 +08:00
parent 7a5ed4801a
commit 748fe05362
2 changed files with 16 additions and 3 deletions

View File

@ -3,9 +3,17 @@
_cli_zsh_autocomplete() {
local -a opts
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
local cur
cur=${words[-1]}
if [[ "$cur" == "-"* ]]; then
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
else
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
fi
_describe 'values' opts
if [[ "${opts[1]}" != "" ]]; then
_describe 'values' opts
fi
return
}

View File

@ -21,9 +21,14 @@ cli v2 manual
* [Exit code](#exit-code)
* [Combining short options](#combining-short-options)
* [Bash Completion](#bash-completion)
+ [Default auto-completion](#default-auto-completion)
+ [Custom auto-completion](#custom-auto-completion)
+ [Enabling](#enabling)
+ [Distribution](#distribution)
+ [Distribution and Persistent Autocompletion](#distribution-and-persistent-autocompletion)
+ [Customization](#customization)
+ [ZSH Support](#zsh-support)
+ [ZSH default auto-complete example](#zsh-default-auto-complete-example)
+ [ZSH custom auto-complete example](#zsh-custom-auto-complete-example)
* [Generated Help Text](#generated-help-text)
+ [Customization](#customization-1)
* [Version Flag](#version-flag)