Add bash completion to glance client

Currently glance client does not support command completion.
The intention is to add this functionality to the client

blueprint add-bash-completion

Change-Id: I725dd308118b101e87182acf0cee6dbfd214e0e4
This commit is contained in:
Michal Dulko
2014-08-22 12:14:10 +02:00
parent 6987295884
commit 12a3a82734
3 changed files with 91 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
_glance_opts="" # lazy init
_glance_flags="" # lazy init
_glance_opts_exp="" # lazy init
_glance()
{
local cur prev nbc cflags
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ "x$_glance_opts" == "x" ] ; then
nbc="`glance bash-completion | sed -e "s/ *-h */ /" -e "s/ *-i */ /"`"
_glance_opts="`echo "$nbc" | sed -e "s/--[a-z0-9_-]*//g" -e "s/ */ /g"`"
_glance_flags="`echo " $nbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/ */ /g"`"
_glance_opts_exp="`echo "$_glance_opts" | sed 's/^ *//' | tr ' ' '|'`"
fi
if [[ " ${COMP_WORDS[@]} " =~ " "($_glance_opts_exp)" " && "$prev" != "help" ]] ; then
COMPREPLY=($(compgen -W "${_glance_flags}" -- ${cur}))
else
COMPREPLY=($(compgen -W "${_glance_opts}" -- ${cur}))
fi
return 0
}
complete -F _glance glance