From 6193aae23408d4bedb33c562eceb5a8cc4579493 Mon Sep 17 00:00:00 2001 From: Dominik Heidler Date: Mon, 14 May 2012 15:47:42 +0200 Subject: [PATCH] add nova-manage bash completion script Change-Id: I856349fb0b31f32ec4570c74ebceb3563fa22547 --- nova-manage.bash_completion | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 nova-manage.bash_completion diff --git a/nova-manage.bash_completion b/nova-manage.bash_completion new file mode 100644 index 0000000..053d419 --- /dev/null +++ b/nova-manage.bash_completion @@ -0,0 +1,37 @@ +# bash completion for openstack nova-manage + +_nova_manage_opts="" # lazy init +_nova_manage_opts_exp="" # lazy init + +# dict hack for bash 3 +_set_nova_manage_subopts () { + eval _nova_manage_subopts_"$1"='$2' +} +_get_nova_manage_subopts () { + eval echo '${_nova_manage_subopts_'"$1"'#_nova_manage_subopts_}' +} + +_nova_manage() +{ + local cur prev subopts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [ "x$_nova_manage_opts" == "x" ] ; then + _nova_manage_opts="`nova-manage bash-completion 2>/dev/null`" + _nova_manage_opts_exp="`echo $_nova_manage_opts | sed -e "s/\s/|/g"`" + fi + + if [[ " `echo $_nova_manage_opts` " =~ " $prev " ]] ; then + if [ "x$(_get_nova_manage_subopts "$prev")" == "x" ] ; then + subopts="`nova-manage bash-completion $prev 2>/dev/null`" + _set_nova_manage_subopts "$prev" "$subopts" + fi + COMPREPLY=($(compgen -W "$(_get_nova_manage_subopts "$prev")" -- ${cur})) + elif [[ ! " ${COMP_WORDS[@]} " =~ " "($_nova_manage_opts_exp)" " ]] ; then + COMPREPLY=($(compgen -W "${_nova_manage_opts}" -- ${cur})) + fi + return 0 +} +complete -F _nova_manage nova-manage