mirror of
https://github.com/spf13/cobra
synced 2024-11-04 21:07:19 +00:00
Enable bash completion after --flag= or --flag=abc
This commit is contained in:
parent
1bacefc9a2
commit
7d556a0974
1 changed files with 21 additions and 2 deletions
|
@ -34,7 +34,7 @@ __debug()
|
|||
__my_init_completion()
|
||||
{
|
||||
COMPREPLY=()
|
||||
_get_comp_words_by_ref cur prev words cword
|
||||
_get_comp_words_by_ref "$@" cur prev words cword
|
||||
}
|
||||
|
||||
__index_of_word()
|
||||
|
@ -76,6 +76,25 @@ __handle_reply()
|
|||
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||
[[ $COMPREPLY == *= ]] || compopt +o nospace
|
||||
fi
|
||||
|
||||
# complete after --flag=abc
|
||||
if [[ $cur == *=* ]]; then
|
||||
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||
compopt +o nospace
|
||||
fi
|
||||
|
||||
local index flag
|
||||
flag="${cur%%=*}"
|
||||
__index_of_word "${flag}" "${flags_with_completion[@]}"
|
||||
if [[ ${index} -ge 0 ]]; then
|
||||
COMPREPLY=() PREFIX="" cur="${cur#*=}"
|
||||
${flags_completion[${index}]}
|
||||
if [ -n "${ZSH_VERSION}" ]; then
|
||||
# zfs completion needs --flag= prefix
|
||||
eval COMPREPLY=( "\${COMPREPLY[@]/#/${flag}=}" )
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
return 0;
|
||||
;;
|
||||
esac
|
||||
|
@ -229,7 +248,7 @@ func postscript(w io.Writer, name string) error {
|
|||
if declare -F _init_completion >/dev/null 2>&1; then
|
||||
_init_completion -s || return
|
||||
else
|
||||
__my_init_completion || return
|
||||
__my_init_completion -n "=" || return
|
||||
fi
|
||||
|
||||
local c=0
|
||||
|
|
Loading…
Reference in a new issue