39 lines
803 B
Text
39 lines
803 B
Text
|
#compdef vb
|
||
|
|
||
|
_vb() {
|
||
|
local state
|
||
|
|
||
|
_arguments -C '1: :->actions' '2: :->vms' '3: :->snapshots'
|
||
|
|
||
|
|
||
|
case $state in
|
||
|
(actions)
|
||
|
local actions
|
||
|
actions=("list:List all VMs"
|
||
|
"start:Start VM"
|
||
|
"stop:Stop VM"
|
||
|
"suspend:Suspend VM"
|
||
|
"restart:Restart VM"
|
||
|
"reset:Reset VM"
|
||
|
"status:Show status"
|
||
|
"snapshot:Create new snapshot"
|
||
|
"snaprestore:Restore snapshots"
|
||
|
"snaplist:List snapshots"
|
||
|
"snapdel:Delete snapshot")
|
||
|
_describe 'actions' actions
|
||
|
;;
|
||
|
(vms)
|
||
|
compadd -- $(vboxmanage list vms | awk '{print $1}' | xargs)
|
||
|
;;
|
||
|
(snapshots)
|
||
|
local snapshot_list
|
||
|
[[ $line[1] =~ 'snapdel|snaprestore' ]] || return
|
||
|
snapshot_list=$(vboxmanage snapshot $line[2] list)
|
||
|
[[ $? -ne 0 ]] && return
|
||
|
compadd -- $(awk '{print $2}' <<<$snapshot_list)
|
||
|
;;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
_vb "$@"
|