mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-22 17:57:46 +03:00
Improved bash completion script
git-svn-id: http://svn.opennebula.org/one/trunk@874 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
b92d70bb0a
commit
ebbb432395
@ -9,11 +9,15 @@ _one_list() {
|
||||
}
|
||||
|
||||
_onevm() {
|
||||
local cur prev opts
|
||||
local cur prev opts cmd
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
if [ "${#COMP_WORDS[@]}" -gt "2" ]; then
|
||||
pprev="${COMP_WORDS[COMP_CWORD-2]}"
|
||||
fi
|
||||
opts="create deploy shutdown livemigrate migrate hold release stop cancel suspend resume delete restart list show top history"
|
||||
cmd=onevm
|
||||
if [ $COMP_CWORD == 1 ]
|
||||
then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
@ -22,12 +26,12 @@ _onevm() {
|
||||
then
|
||||
case "$prev" in
|
||||
show|delete)
|
||||
vms=`_one_list onevm`
|
||||
vms=`_one_list $cmd`
|
||||
COMPREPLY=( $(compgen -W "${vms}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
cancel|shutdown|suspend)
|
||||
vms=`_one_list onevm stat='runn'`
|
||||
cancel|shutdown|suspend|stop)
|
||||
vms=`_one_list $cmd stat='runn'`
|
||||
COMPREPLY=( $(compgen -W "${vms}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
@ -35,18 +39,33 @@ _onevm() {
|
||||
COMPREPLY=( $(compgen -A file -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
migrate)
|
||||
vms=`_one_list $cmd stat='runn'`
|
||||
COMPREPLY=( $(compgen -W "${vms}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
elif [ $COMP_CWORD == 3 ]
|
||||
then
|
||||
case "$pprev" in
|
||||
migrate)
|
||||
hosts=`onehost list -f STAT=on|sed 1d|awk '{print $2}'`
|
||||
COMPREPLY=( $(compgen -W "${hosts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _onevm onevm
|
||||
|
||||
_onevnet() {
|
||||
local cur prev opts
|
||||
local cur prev opts cmd
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="create delete list show"
|
||||
cmd=onevnet
|
||||
if [ $COMP_CWORD == 1 ]
|
||||
then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
@ -59,7 +78,7 @@ _onevnet() {
|
||||
return 0
|
||||
;;
|
||||
delete|show)
|
||||
vnets=`_one_list onevnet`
|
||||
vnets=`_one_list $cmd`
|
||||
COMPREPLY=( $(compgen -W "${vnets}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
@ -69,3 +88,43 @@ _onevnet() {
|
||||
}
|
||||
|
||||
complete -F _onevnet onevnet
|
||||
|
||||
_onehost() {
|
||||
local cur prev opts cmd
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="create show delete list enable disable top"
|
||||
cmd=onehost
|
||||
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)
|
||||
hosts=`_one_list $cmd`
|
||||
COMPREPLY=( $(compgen -W "${hosts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
enable)
|
||||
hosts=`_one_list $cmd stat='off'`
|
||||
COMPREPLY=( $(compgen -W "${hosts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
disable)
|
||||
hosts=`_one_list $cmd stat='on'`
|
||||
COMPREPLY=( $(compgen -W "${hosts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
complete -F _onehost onehost
|
||||
|
Loading…
x
Reference in New Issue
Block a user