vbox.zsh (1362B)
1 #compdef vbox 2 _vboxmachines() { 3 VBoxManage list vms | egrep -o '^"[^"]+"' 2>/dev/null | sed -e 's|"||g' | while read machine; do 4 _wanted 'machine' expl 'machine' compadd $machine 5 done 6 } 7 _vbox() { 8 local -a arguments 9 arguments=( 10 'start:start a VM' 11 'startgui:start a VM in GUI mode' 12 'stop:stop a VM' 13 'open:open a VM, starting it if necessary' 14 'pause:pause a VM' 15 'suspend:suspend a VM' 16 'resume:resume a paused VM' 17 'ls:list known VMs' 18 'info:get information about a VM' 19 'status:get status of a VM' 20 'running:list currently running VMs' 21 'share:share a local folder' 22 'unshare:unshare a local folder' 23 'sharetmp:temporarily share a local folder' 24 'shared:list shared folders for a VM' 25 ) 26 local context state line expl 27 local -A opt_args 28 _arguments '*:: :->subcmds' && return 0 29 30 if (( CURRENT == 1 )); then 31 _describe -t commands "vbox commands" arguments -V1 32 return 33 fi 34 35 case "$words[1]" in 36 share|sharetmp) 37 _arguments \ 38 ':hostpath:_files -/' \ 39 :machine:_vboxmachines \ 40 ':name: :' 41 ;; 42 unshare) 43 _arguments \ 44 ':hostpath:_files -/' \ 45 :machine:_vboxmachines 46 ;; 47 start|startgui|stop|open|status|info|shared|pause|suspend|resume) 48 _arguments \ 49 :machine:_vboxmachines 50 ;; 51 esac 52 return 1 53 }