diff options
author | Dominik Heidler <dheidler@suse.de> | 2012-05-15 11:25:11 +0200 |
---|---|---|
committer | Dominik Heidler <dheidler@suse.de> | 2012-05-16 09:54:43 +0200 |
commit | c9495134690a1818fccfec0b8a5717dc31ea5633 (patch) | |
tree | 40183b19e8fd84940be01736a63b58bcd889dc2c /tools | |
parent | 66522fdc9c09a65b87fe412e7bea87e4761ec43d (diff) | |
download | python-novaclient-c9495134690a1818fccfec0b8a5717dc31ea5633.tar.gz |
make nova bash-complete faster and more accurate
- cache output of "nova bash-complete"
- distinguish between flags and commands (based on already typed text)
Change-Id: I85bd1c2198eef222540cf12063a3b233b0d6db12
Diffstat (limited to 'tools')
-rw-r--r-- | tools/nova.bash_completion | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/tools/nova.bash_completion b/tools/nova.bash_completion index 90d16c0c..43390052 100644 --- a/tools/nova.bash_completion +++ b/tools/nova.bash_completion @@ -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 |