1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-06 12:58:18 +03:00

Added the first draft of the bash_completion scripts of one commands

git-svn-id: http://svn.opennebula.org/one/trunk@785 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Jaime Melis 2009-09-08 13:15:23 +00:00
parent efaa7a92a5
commit 5ba13871cc

View File

@ -0,0 +1,71 @@
_one_list() {
local cmd filter
one_cmd=$1
if [ -n "$2" ]; then
filter="-f $2"
fi
echo $($one_cmd $filter list|sed 1d|awk '{print $1}')
return 0
}
_onevm() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="create deploy shutdown livemigrate migrate hold release stop cancel suspend resume delete restart list show top history"
if [ $COMP_CWORD == 1 ]
then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
elif [ $COMP_CWORD == 2 ]
then
case "$prev" in
show|delete)
vms=`_one_list onevm`
COMPREPLY=( $(compgen -W "${vms}" -- ${cur}) )
return 0
;;
cancel|shutdown|suspend)
vms=`_one_list onevm stat='runn'`
COMPREPLY=( $(compgen -W "${vms}" -- ${cur}) )
return 0
;;
create|submit)
COMPREPLY=( $(compgen -A file -- ${cur}) )
return 0
;;
esac
fi
}
complete -F _onevm onevm
_onevnet() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="create delete list show"
if [ $COMP_CWORD == 1 ]
then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
elif [ $COMP_CWORD == 2 ]
then
case "$prev" in
create|submit)
COMPREPLY=( $(compgen -A file -- ${cur}) )
return 0
;;
delete|show)
vnets=`_one_list onevnet`
COMPREPLY=( $(compgen -W "${vnets}" -- ${cur}) )
return 0
;;
esac
fi
}
complete -F _onevnet onevnet