Merge "make nova bash-complete faster and more accurate"

This commit is contained in:
Jenkins 2012-05-23 14:52:05 +00:00 committed by Gerrit Code Review
commit d15f216b2d
2 changed files with 22 additions and 9 deletions

View File

@ -18,6 +18,7 @@ Dan Prince <dprince@redhat.com>
Dan Wendlandt <dan@nicira.com>
Dave Walker <Dave.Walker@canonical.com>
Dean Troyer <dtroyer@gmail.com>
Dominik Heidler <dheidler@suse.de>
Ed Leafe <ed@leafe.com>
Edouard Thuleau <edouard1.thuleau@orange.com>
Eldar Nugaev <eldr@ya.ru>

View File

@ -1,15 +1,27 @@
_nova_opts="" # lazy init
_nova_flags="" # lazy init
_nova_opts_exp="" # lazy init
_nova()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
local cur prev nbc cflags
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="$(nova bash_completion)"
if [ "x$_nova_opts" == "x" ] ; then
nbc="`nova bash-completion`"
_nova_opts="`echo "$nbc" | sed -e "s/--[a-z0-9_-]*//g" -e "s/\s\s*/ /g"`"
_nova_flags="`echo " $nbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/\s\s*/ /g"`"
_nova_opts_exp="`echo "$_nova_opts" | sed -e "s/\s/|/g"`"
fi
COMPLETION_CACHE=~/.novaclient/*/*-cache
opts+=" "$(cat $COMPLETION_CACHE 2> /dev/null | tr '\n' ' ')
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
if [[ " ${COMP_WORDS[@]} " =~ " "($_nova_opts_exp)" " && "$prev" != "help" ]] ; then
COMPLETION_CACHE=~/.novaclient/*/*-cache
cflags="$_nova_flags "$(cat $COMPLETION_CACHE 2> /dev/null | tr '\n' ' ')
COMPREPLY=($(compgen -W "${cflags}" -- ${cur}))
else
COMPREPLY=($(compgen -W "${_nova_opts}" -- ${cur}))
fi
return 0
}
complete -F _nova nova