forked from zsh-users/zsh-completions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_virtualbox
312 lines (292 loc) · 11.1 KB
/
_virtualbox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#compdef VBoxManage=vboxmanage VBoxHeadless=vboxheadless
# ------------------------------------------------------------------------------
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the zsh-users nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for VirtualBox (http://www.virtualbox.org).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Massimiliano Torromeo <[email protected]>
# * Julien Nicoulaud <[email protected]>
#
# ------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------
_vboxmachines() {
VBoxManage list vms | egrep -o '^"[^"]+"' 2>/dev/null | sed -e 's|"||g' | while read machine; do
_wanted 'machine' expl 'machine' compadd $machine
done
}
# Roughly guess command options
_vboxcommandoptions() {
cmd="$1"
cmdoutput=$(VBoxManage "$cmd" 2>/dev/null | tail -n +2 | grep -v 'Syntax error:' | grep -v '<uuid>|<name>' | sed 's|<[^>]\+>||g' | sed 's|VBoxManage [^ ]\+ | |')
optcount=0
option=""
optlines=()
echo "$cmdoutput" | egrep -o ' [\[A-Za-z0-9\-\<].*' | while read line; do
option="${option}${line}"
if [[ $line[-1] != '|' ]]; then
optcount=$(($optcount+1))
optlines[$optcount]="$option"
option=""
fi
done
# optionals ([abc])
for line in $optlines; do
echo "$line" | egrep -o '\[[^]]+\]' | while read option; do
option=$(echo $option | sed 's|[]\[]||g' | cut -d ' ' -f 1)
_options=(${(s:|:)option})
for option in $_options; do
_wanted "${cmd}_option" expl "${cmd} option" compadd -- $option
done
done
done
# mandatory
for line in $optlines; do
echo "$line" | sed 's|\[[^]]\+\]|\n|g' | while read option; do
if [[ "$option" != "" ]]; then
_option=$(echo $option | cut -d ' ' -f 1)
_options=(${(s:|:)option})
for option in $_options; do
_wanted "${cmd}_option" expl "${cmd} option" compadd -- $option
done
fi
done
done
}
# List possible mediums
_vboxmediums() {
_wanted "mediums" expl "mediums" compadd -- "none"
_wanted "mediums" expl "mediums" compadd -- "emptydrive"
_wanted "mediums" expl "mediums" compadd -- "iscsi"
_files -g '*.{iso,vmdk,vdi}'
for CD in /dev/cd/*; do
readlink -f $CD
done | uniq | while read CD; do
_wanted "host drives" expl "host drives" compadd -- "host:$CD"
done
}
# List available os types
_vboxostypes() {
VBoxManage list ostypes | grep '^ID' | awk '{print $2}' | while read OSTYPE; do
_wanted 'ostype' expl 'os type' compadd -- $OSTYPE
done
}
# Guess options for this commands
_vboxopts_controlvm() { _vboxcommandoptions controlvm }
_vboxopts_modifyvm() { _vboxcommandoptions modifyvm }
_vboxopts_export() { _vboxcommandoptions export }
_vboxmanage() {
local -a _1st_arguments
_1st_arguments=(
"list:gives information about VirtualBox's current settings"
'showvminfo:shows information about a particular virtual machine'
'registervm:import a virtual machine definition in an XML file into VirtualBox'
'unregistervm:unregisters a virtual machine'
'createvm:creates a new XML virtual machine definition file'
'modifyvm:changes the properties of a registered virtual machine which is not running'
'import:imports a virtual appliance in OVF format by copying the virtual disk images and creating virtual machines in VirtualBox'
'export:exports one or more virtual machines from VirtualBox into a virtual appliance in OVF format'
'startvm:starts a virtual machine that is currently in the "Powered off" or "Saved" states'
'controlvm:change the state of a virtual machine that is currently running'
'discardstate:discards the saved state of a virtual machine which is not currently running'
'adoptstate:adopt a saved state file (.sav)'
'snapshot:control snapshots'
'closemedium:removes a hard disk, DVD or floppy image from a VirtualBox media registry'
'storageattach:attaches/modifies/removes a storage medium connected to a storage controller'
'storagectl:attaches/modifies/removes a storage controller'
'bandwidthctl:creates/deletes/modifies bandwidth groups'
'showhdinfo:shows information about a virtual hard disk image'
'createhd:creates a new virtual hard disk image'
'modifyhd:change the characteristics of a disk image after it has been created'
'clonehd:duplicates a registered virtual hard disk image to a new image file with a new unique identifier'
'convertfromraw:converts a raw disk image to a VirtualBox Disk Image (VDI) file'
'getextradata:retrieve string data to a virtual machine or to a VirtualBox configuration'
'setextradata:attach string data to a virtual machine or to a VirtualBox configuration'
'setproperty:change global settings which affect the entire VirtualBox installation'
'usbfilter:used for working with USB filters in virtual machines, or global filters'
'sharedfolder:share folders on the host computer with guest operating systems'
'guestproperty:get or set properties of a running virtual machine'
'guestcontrol:control certain things inside a guest from the host'
'debugvm:for experts who want to tinker with the exact details of virtual machine execution'
'metrics:monitor the usage of system resources'
'hostonlyif:change the IP configuration of a host-only network interface'
'dhcpserver:control the DHCP server that is built into VirtualBox'
'extpack:add or remove VirtualBox extension packs'
)
local context state line expl
local -A opt_args
_arguments '*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "VBoxManage commands" _1st_arguments -V1
return
fi
case "$words[1]" in
list)
_arguments \
'--long' \
':list option:(vms runningvms ostypes hostdvds hostfloppies bridgedifs hostonlyifs dhcpservers hostinfo hostcpuids hddbackends hdds dvds floppies usbhost usbfilters systemproperties extpacks)'
;;
showvminfo)
_arguments \
:machine:_vboxmachines \
'--details' \
'--machinereadable' \
'--log: :'
;;
unregistervm)
_arguments \
:machine:_vboxmachines \
'--delete'
;;
createvm)
_arguments \
'--name: :' \
'--ostype:os type:_vboxostypes' \
'--register' \
'--basefolder:folder:_files -/' \
'--settingsfile:file:_files' \
'--uuid: :'
;;
modifyvm)
_arguments \
:machine:_vboxmachines \
:modifyvm_option:_vboxopts_modifyvm
;;
import)
_arguments \
':ovf file:_files -g \*.{ovf,ova}' \
'--dry-run'
;;
export)
_arguments \
:machine:_vboxmachines \
:export_option:_vboxopts_export
;;
startvm)
_arguments \
:machine:_vboxmachines \
'--type:running mode:(gui sdl headless)'
;;
controlvm)
_arguments \
:machine:_vboxmachines \
:controlvm_option:_vboxopts_controlvm
;;
adoptstate)
_arguments \
:machine:_vboxmachines \
':sav file:_files -g \*.sav'
;;
closemedium)
_arguments \
':type:(disk dvd floppy)' \
':file:_files' \
'--delete'
;;
discardstate|bandwidthctl|getextradata|setextradata|debugvm)
_arguments \
:machine:_vboxmachines
;;
storagectl)
_arguments \
:machine:_vboxmachines \
'--name: :' \
'--add:type:(ide scsi floppy sas)' \
'--controller:type:(LSILogic|LSILogicSAS|BusLogic|IntelAHCI|PIIX3|PIIX4|ICH6|I82078)' \
--sataideemulation{1..4}":port:({1..30})" \
"--sataportcount:num:({1..30})" \
'--hostiocache:bool:(on off)' \
'--bootable:bool:(on off)' \
'--remove' #"
;;
storageattach)
_arguments \
:machine:_vboxmachines\
'--storagectl:storage ctl:("IDE Controller" "SATA Controller")' \
'--port: :' \
'--device: :' \
'--type:drive type:(dvddrive hdd fdd)' \
'--medium:mediums:_vboxmediums' \
'--mtype:behaviour:(normal writethrough immutable shareable)' \
'--comment: :' \
'--passthrough:enabled?:(on off)' \
'--bandwidthgroup: :' \
'--forceunmount' '--server: :' \
'--target: :' \
'--lun: :' \
'--encodedlun: :' \
'--username: :' \
'--password: :' \
'--intnet: :'
;;
createhd)
_arguments \
'--filename:filename:_files -g \*.{vdi,vmdk,vhd}' \
'--size:megabytes:' \
'--sizebyte:bytes:' \
'--format:type:(VDI VMDK VHD)' \
'--variant:type:(Standard Fixed Split2G Stream ESX)'
;;
sharedfolder)
_arguments \
':action:(add remove)' \
:machine:_vboxmachines \
'--name: :' \
'--hostpath:path:_files -/' \
'--transient' \
'--readonly' \
'--automount'
;;
esac
return 1
}
_vboxheadless() {
local context state line expl
local -A opt_args
_arguments \
'(-s -startvm --startvm)'{-s,-startvm,--startvm}'[Start given VM]:machine:_vboxmachines' \
'(-n --vnc)'{-n,--vnc}'[Enable the built in VNC server]' \
'(-m --vncport)'{-m,--vncport}'[TCP port number to use for the VNC server]:port:' \
'(-o --vncpass)'{-o,--vncpass}'[Set the VNC server password]:pw:' \
'(-v -vrde --vrde)'{-v,-vrde,--vrde}"[Enable (default) or disable the VRDE server or don't change the setting]::(on off config)" \
'(-e -vrdeproperty --vrdeproperty)'{-e,-vrdeproperty,--vrdeproperty}'[Set a VRDE property]: :' \
'(-c -capture --capture)'{-c,-capture,--capture}'[Record the VM screen output to a file]' \
'(-w --width)'{-w,--width}'[Frame width when recording]:width:' \
'(-h --height)'{-h,--height}'[Frame height when recording]:height:' \
'(-r --bitrate)'{-r,--bitrate}'[Recording bit rate when recording]:bitrate:' \
'(-f --filename)'{-f,--filename}'[File name when recording. The codec used will be chosen based on the file extension]:filename:_files'
}
_virtualbox() {
local ret=1
_call_function ret _$service
return ret
}
_virtualbox "$@"