ad4f2b34b7
Make bash completion script generated automatically by using 'mistral bash-completion' commands Add a unit test for 'bash-completion' command. Partially Implements: blueprint bash-completion-script-optimization Change-Id: I97b15a1b9f41f98f5928f8bda4769957a37678d2
26 lines
784 B
Plaintext
26 lines
784 B
Plaintext
_mistral_opts="" # lazy init
|
|
_mistral_flags="" # lazy init
|
|
_mistral_opts_exp="" # lazy init
|
|
_mistral()
|
|
{
|
|
local cur prev mbc cflags
|
|
COMPREPLY=()
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
if [ "x$_mistral_opts" == "x" ] ; then
|
|
mbc="`mistral bash-completion`"
|
|
_mistral_opts="`echo "$mbc" | sed -e "s/\s-[a-z0-9_-]*//g" -e "s/\s\s*/ /g"`"
|
|
_mistral_flags="`echo " $mbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/\s\s*/ /g"`"
|
|
_mistral_opts_exp="`echo "$_mistral_opts" | sed -e "s/\s/|/g"`"
|
|
fi
|
|
|
|
if [[ " ${COMP_WORDS[@]} " =~ " "($_mistral_opts_exp)" " && "$prev" != "help" ]] ; then
|
|
COMPREPLY=($(compgen -W "${_mistral_flags}" -- ${cur}))
|
|
else
|
|
COMPREPLY=($(compgen -W "${_mistral_opts}" -- ${cur}))
|
|
fi
|
|
return 0
|
|
}
|
|
complete -F _mistral mistral
|