mirror of
https://github.com/gryf/vboxmanage-bash-completion.git
synced 2025-12-19 04:20:25 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8301459df | |||
| ab0cc7aea4 | |||
| f73e80c7ad | |||
| 10900543fa |
@@ -6,7 +6,7 @@ script. However, in some point of time I've decided to rewrite it almost from
|
||||
scratch.
|
||||
|
||||
Current version of script was written and tested against VBoxManage in version
|
||||
5.2.32, and supports all commands (in some extent ;)).
|
||||
6.0.12, and should contain all commands and their options.
|
||||
|
||||
Unlike other attempts, I've tried to make the script context aware. See the
|
||||
simple session with the VBoxManage command below, to have an idea how it works:
|
||||
|
||||
205
VBoxManage
205
VBoxManage
@@ -4,7 +4,7 @@
|
||||
# URL: https://bitbucket.org/gryf/vboxmanage-bash-completion
|
||||
# URL: https://github.com/gryf/vboxmanage-bash-completion
|
||||
# License: 3-clause BSD-style license (see LICENSE file)
|
||||
# Version: 5.2.32
|
||||
# Version: 6.0.12
|
||||
|
||||
_VBoxManage() {
|
||||
local cur prev opts cmd subcommand tmp items name index result
|
||||
@@ -323,14 +323,10 @@ _VBoxManage() {
|
||||
|
||||
_list_comp() {
|
||||
local list
|
||||
list=$(VBoxManage list | \
|
||||
grep '|' | \
|
||||
sed 's/\[.*\]//g'| \
|
||||
sed 's/VBoxManage list//' | \
|
||||
tr "\\n" " " | \
|
||||
sed 's/$/\n/' | \
|
||||
sed 's/\s\+//g' | \
|
||||
sed 's/|/ /g')
|
||||
list=$(VBoxManage list | sed -e '1,2d' \
|
||||
-e 's/VBoxManage list //' \
|
||||
-e 's/[\[\]\|]/ /g' \
|
||||
-e 's/|/ /g'|xargs echo)
|
||||
COMPREPLY=( $(compgen -W "$list" -- ${cur}) )
|
||||
}
|
||||
|
||||
@@ -456,9 +452,9 @@ _VBoxManage() {
|
||||
sort | \
|
||||
uniq)
|
||||
|
||||
# add debugvm command manually, since it's described differently in
|
||||
# vboxmanage help
|
||||
opts="${opts} debugvm unattended"
|
||||
# Add some commands manually, since they are listed differently in
|
||||
# vboxmanage help.
|
||||
opts="${opts} mediumio debugvm unattended extpack"
|
||||
|
||||
if [[ ${cur} == "-q" || ${COMP_CWORD} -eq 1 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
@@ -583,7 +579,7 @@ _VBoxManage() {
|
||||
;;
|
||||
--options)
|
||||
COMPREPLY=( $(compgen -W "link keepallmacs keepnatmacs
|
||||
keepdisknames" -- ${cur}) )
|
||||
keepdisknames keephwuuids" -- ${cur}) )
|
||||
;;
|
||||
--groups)
|
||||
COMPREPLY=()
|
||||
@@ -641,18 +637,17 @@ _VBoxManage() {
|
||||
setlinkstate3 setlinkstate4 setlinkstate5 setlinkstate6
|
||||
setlinkstate7 setlinkstate8 setvideomodehint teleport unplugcpu
|
||||
usbattach usbdetach vrde vrdeport vrdeproperty
|
||||
vrdevideochannelquality webcam videocap videocapscreens
|
||||
videocapfile videocapres videocaprate videocapfps
|
||||
videocapmaxtime videocapmaxsize addencpassword removeencpassword
|
||||
removeallencpasswords keyboardputstring keyboardputfile audioin
|
||||
audioout)
|
||||
vrdevideochannelquality webcam recording addencpassword
|
||||
removeencpassword removeallencpasswords keyboardputstring
|
||||
keyboardputfile audioin audioout setscreenlayout changeuartmode1
|
||||
changeuartmode2)
|
||||
|
||||
_find_item_name 2
|
||||
subcommand=${COMP_WORDS[$((index+1))]}
|
||||
|
||||
if [[ " ${items[@]} " == *" $subcommand "* ]]; then
|
||||
case "${subcommand}" in
|
||||
videocapfile|keyboardputfile|nictracefile[1-8])
|
||||
keyboardputfile|nictracefile[1-8])
|
||||
[[ ${prev} == "nictracefile"* ]] && \
|
||||
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||
;;
|
||||
@@ -689,11 +684,25 @@ _VBoxManage() {
|
||||
COMPREPLY=( $(compgen -W "disabled hosttoguest
|
||||
guesttohost bidirectional" -- ${cur}) )
|
||||
;;
|
||||
vrde|videocap)
|
||||
[[ ${prev} == "vrde" ||
|
||||
${prev} == "videocap" ]] && \
|
||||
vrde)
|
||||
[[ ${prev} == "vrde" ]] && \
|
||||
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
||||
;;
|
||||
recording)
|
||||
[[ ${prev} == "recording" ]] && \
|
||||
COMPREPLY=( $(compgen -W "on off screens
|
||||
filename videores videorate videofps maxtime
|
||||
maxfilesize" -- ${cur}) )
|
||||
case "${prev}" in
|
||||
screens)
|
||||
COMPREPLY=( $(compgen -W "all none
|
||||
<screen>" -- ${cur}) )
|
||||
;;
|
||||
filename)
|
||||
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
videocapscreens)
|
||||
[[ ${prev} == "videocapscreens" ]] && \
|
||||
COMPREPLY=( $(compgen -W "all none" -- ${cur}) )
|
||||
@@ -732,6 +741,12 @@ _VBoxManage() {
|
||||
_get_excluded_items "${tmp[@]}"
|
||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||
;;
|
||||
changeuartmode[1-2])
|
||||
tmp=(disconnected server client tcpserver tcpclient
|
||||
file "<devicename>")
|
||||
_get_excluded_items "${tmp[@]}"
|
||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||
;;
|
||||
esac
|
||||
elif [[ ${prev} == "--passwordfile" || ${prev} == "--capturefile" ]]; then
|
||||
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||
@@ -792,7 +807,7 @@ _VBoxManage() {
|
||||
;;
|
||||
--variant)
|
||||
COMPREPLY=( $(compgen -W "Standard Fixed Split2G
|
||||
Stream ESX" -- ${cur}) )
|
||||
Stream ESX Formatted" -- ${cur}) )
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
@@ -801,7 +816,8 @@ _VBoxManage() {
|
||||
;;
|
||||
|
||||
createvm)
|
||||
items=(--name --groups --ostype --register --basefolder --uuid)
|
||||
items=(--name --groups --ostype --register --basefolder --uuid
|
||||
--default)
|
||||
if [[ ${prev} == ${cmd} ]]; then
|
||||
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||
else
|
||||
@@ -887,7 +903,7 @@ _VBoxManage() {
|
||||
if [[ " ${items[@]} " == *" $subcommand "* ]]; then
|
||||
case "${subcommand}" in
|
||||
add|modify)
|
||||
items=(--ip --netmask --lowerip --upperip)
|
||||
items=(--ip --netmask --lowerip --upperip --options)
|
||||
|
||||
[[ " ${COMP_WORDS[@]} " != *" --ifname"* &&
|
||||
" ${COMP_WORDS[@]} " != *" --netname"* ]] &&
|
||||
@@ -897,6 +913,9 @@ _VBoxManage() {
|
||||
" ${COMP_WORDS[@]} " != *" --disable"* ]] &&
|
||||
items+=(--enable --disable)
|
||||
|
||||
[[ " ${COMP_WORDS[@]} " == *" --options"* ]] &&
|
||||
items+=(--vm --nic --id --value --remove)
|
||||
|
||||
_get_excluded_items "${items[@]}"
|
||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||
;;
|
||||
@@ -945,11 +964,15 @@ _VBoxManage() {
|
||||
;;
|
||||
|
||||
"export")
|
||||
items=( --manifest --iso --options --vsys)
|
||||
items=( --manifest --iso --options --vsys --cloud)
|
||||
if [[ ${prev} == ${cmd} ]]; then
|
||||
_vms_comp vms
|
||||
elif [[ ${prev} == "--eulafile" ]]; then
|
||||
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||
elif [[ ${prev} == "--cloudkeepobject" ||
|
||||
${prev} == "--cloudlaunchinstance" ||
|
||||
${prev} == "--cloudpublicip" ]]; then
|
||||
COMPREPLY=( $(compgen -W "true false" -- ${cur}) )
|
||||
else
|
||||
[[ " ${COMP_WORDS[@]} " != *" -o "* &&
|
||||
" ${COMP_WORDS[@]} " != *" --output "* ]] &&
|
||||
@@ -962,7 +985,11 @@ _VBoxManage() {
|
||||
items+=(--legacy09 --ovf09 --ovf10 --ovf20 --opc10)
|
||||
[[ " ${COMP_WORDS[@]} " == *" --vsys "* ]] &&
|
||||
items+=(--product --producturl --vendor --vendorurl
|
||||
--version --description --eula --eulafile)
|
||||
--version --description --eula --eulafile --vmname)
|
||||
[[ " ${COMP_WORDS[@]} " == *" --cloud"* ]] &&
|
||||
items+=(--vmname --cloudprofile --cloudshape --clouddomain
|
||||
--clouddisksize --cloudbucket --cloudocivcn --cloudocisubnet
|
||||
--cloudkeepobject --cloudlaunchinstance --cloudpublicip)
|
||||
_get_excluded_items "${items[@]}"
|
||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||
|
||||
@@ -971,6 +998,7 @@ _VBoxManage() {
|
||||
COMPREPLY=( $(compgen -W "manifest iso nomacs
|
||||
nomacsbutnat" -- ${cur}) )
|
||||
;;
|
||||
|
||||
esac
|
||||
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
||||
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||
@@ -1075,8 +1103,8 @@ _VBoxManage() {
|
||||
;;
|
||||
|
||||
copyfrom|copyto)
|
||||
items=(--dryrun --follow --target-directory
|
||||
--username --domain)
|
||||
items=(--follow --target-directory --username
|
||||
--domain)
|
||||
|
||||
[[ " ${COMP_WORDS[@]} " != *" --recursive "* &&
|
||||
" ${COMP_WORDS[@]} " != *" -R "* ]] &&
|
||||
@@ -1438,6 +1466,31 @@ _VBoxManage() {
|
||||
fi
|
||||
;;
|
||||
|
||||
mediumio)
|
||||
if [[ ${prev} == ${cmd} ]]; then
|
||||
_hdd_comp
|
||||
_floppy_comp
|
||||
_dvds_comp
|
||||
else
|
||||
case "${prev}" in
|
||||
formatfat)
|
||||
COMPREPLY=( $(compgen -W "--quick" -- ${cur}) )
|
||||
;;
|
||||
cat)
|
||||
COMPREPLY=( $(compgen -W "--hex --offset --size
|
||||
--output" -- ${cur}) )
|
||||
;;
|
||||
stream)
|
||||
COMPREPLY=( $(compgen -W "--forma --variant
|
||||
--output" -- ${cur}) )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $(compgen -W "--password-file cat formatfat
|
||||
stream" -- ${cur}) )
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
|
||||
mediumproperty)
|
||||
if [[ ${prev} == ${cmd} ]]; then
|
||||
COMPREPLY=( $(compgen -W "disk dvd floppy" -- ${cur}) )
|
||||
@@ -1525,7 +1578,7 @@ _VBoxManage() {
|
||||
*)
|
||||
_find_item_name 2
|
||||
items=(--type --autoreset --property --compact --resize
|
||||
--move --description)
|
||||
--move --description --setlocation)
|
||||
_get_excluded_items "${items[@]}"
|
||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||
case "${prev}" in
|
||||
@@ -1540,6 +1593,9 @@ _VBoxManage() {
|
||||
--move)
|
||||
COMPREPLY=( $(compgen -o dirnames -- ${cur}) )
|
||||
;;
|
||||
--setlocation)
|
||||
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
@@ -1610,18 +1666,19 @@ _VBoxManage() {
|
||||
--audiocontroller --clipboard --draganddrop --vrde --vrdeextpack
|
||||
--vrdeproperty --vrdeport --vrdeaddress --vrdeauthtype
|
||||
--vrdeauthlibrary --vrdemulticon --vrdereusecon --vrdevideochannel
|
||||
--vrdevideochannelquality --usb --usbehci --snapshotfolder
|
||||
--vrdevideochannelquality --usbohci --usbehci --snapshotfolder
|
||||
--teleporter --teleporterport --teleporteraddress
|
||||
--teleporterpassword --teleporterpasswordfile --tracing-enabled
|
||||
--tracing-config --tracing-allow-vm-access --usbcardreader
|
||||
--autostart-enabled --autostart-delay --videocap --videocapscreens
|
||||
--videocapfile --videocapres --videocaprate --videocapfps
|
||||
--videocapmaxtime --videocapmaxsize --videocapopts --defaultfrontend
|
||||
--cpuid-portability-level --paravirtprovider --audiocodec --usbxhci
|
||||
--usbrename --apic --x2apic --paravirtdebug --cpu-profile
|
||||
--biosapic --ibpb-on-vm-entry --ibpb-on-vm-exit --spec-ctrl
|
||||
--audioin --audioout --l1d-flush-on-sched
|
||||
--l1d-flush-on-vm-entry --mds-clear-on-sched --mds-clear-on-vm-entry)
|
||||
--autostart-enabled --autostart-delay --recording --recordingscreens
|
||||
--recordingfile --recordingvideores --recordingvideorate
|
||||
--recordingvideofps --recordingmaxtime --recordingmaxsize
|
||||
--recordingopts --defaultfrontend --cpuid-portability-level
|
||||
--paravirtprovider --audiocodec --usbxhci --usbrename --apic
|
||||
--x2apic --paravirtdebug --cpu-profile --biosapic --ibpb-on-vm-entry
|
||||
--ibpb-on-vm-exit --spec-ctrl --audioin --audioout
|
||||
--l1d-flush-on-sched --l1d-flush-on-vm-entry --mds-clear-on-sched
|
||||
--mds-clear-on-vm-entry --nested-hw-virt --uarttype1 --uarttype2)
|
||||
|
||||
if [[ ${prev} == ${cmd} ]]; then
|
||||
_vms_comp vms
|
||||
@@ -1657,18 +1714,19 @@ _VBoxManage() {
|
||||
--natdnshostresolver3|--natdnshostresolver4|\
|
||||
--natdnshostresolver5|--natdnshostresolver6|\
|
||||
--natdnshostresolver7|--natdnshostresolver8|--vrde|\
|
||||
--vrdemulticon|--vrdereusecon|--vrdevideochannel|--usb|\
|
||||
--vrdemulticon|--vrdereusecon|--vrdevideochannel|--usbohci|\
|
||||
--usbehci|--teleporter|--tracing-enabled|\
|
||||
--tracing-allow-vm-access|--usbcardreader|\
|
||||
--autostart-enabled|--videocap|--usbxhci|--apic|--x2apic|\
|
||||
--autostart-enabled|--recording|--usbxhci|--apic|--x2apic|\
|
||||
--ibpb-on-vm-entry|--ibpb-on-vm-exit|--spec-ctrl|--audioin|\
|
||||
--audioout|--l1d-flush-on-sched|--l1d-flush-on-vm-entry|\
|
||||
--mds-clear-on-sched|--mds-clear-on-vm-entry)
|
||||
--mds-clear-on-sched|--mds-clear-on-vm-entry|\
|
||||
--nested-hw-virt)
|
||||
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--graphicscontroller)
|
||||
COMPREPLY=( $(compgen -W "none vboxvga vmsvga" \
|
||||
COMPREPLY=( $(compgen -W "none vboxvga vmsvga vboxsvga" \
|
||||
-- ${cur}) )
|
||||
;;
|
||||
|
||||
@@ -1743,66 +1801,71 @@ _VBoxManage() {
|
||||
;;
|
||||
|
||||
--natpf[1-8])
|
||||
COMPREPLY+=( $(compgen -W "delete" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "delete" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--nataliasmode[1-8])
|
||||
COMPREPLY+=( $(compgen -W "default" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "default" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--macaddress[1-8])
|
||||
COMPREPLY+=( $(compgen -W "auto" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "auto" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--mouse)
|
||||
COMPREPLY+=( $(compgen -W "ps2 usb usbtablet
|
||||
COMPREPLY=( $(compgen -W "ps2 usb usbtablet
|
||||
usbmultitouch" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--keyboard)
|
||||
COMPREPLY+=( $(compgen -W "ps2 usb" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "ps2 usb" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--uart[1-2]|--lpt[1-2])
|
||||
COMPREPLY+=( $(compgen -W "off" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "off" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--uartmode[1-2])
|
||||
COMPREPLY+=( $(compgen -W "disconnected server client
|
||||
COMPREPLY=( $(compgen -W "disconnected server client
|
||||
tcpserver tcpclient file" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--uarttype[1-2])
|
||||
COMPREPLY=( $(compgen -W "16450 16550A
|
||||
16750" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--audio)
|
||||
COMPREPLY+=( $(compgen -W "none null oss alsa pulse" \
|
||||
COMPREPLY=( $(compgen -W "none null oss alsa pulse" \
|
||||
-- ${cur}) )
|
||||
;;
|
||||
|
||||
--audiocontroller)
|
||||
COMPREPLY+=( $(compgen -W "ac97 hda sb16" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "ac97 hda sb16" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--audiocodec)
|
||||
COMPREPLY+=( $(compgen -W "stac9700 ad1980 stac9221
|
||||
COMPREPLY=( $(compgen -W "stac9700 ad1980 stac9221
|
||||
sb16" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--clipboard)
|
||||
COMPREPLY+=( $(compgen -W "disabled hosttoguest
|
||||
COMPREPLY=( $(compgen -W "disabled hosttoguest
|
||||
guesttohost bidirectional" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--draganddrop)
|
||||
COMPREPLY+=( $(compgen -W "disabled hosttoguest
|
||||
COMPREPLY=( $(compgen -W "disabled hosttoguest
|
||||
guesttohost bidirectional" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--vrdeextpack|--vrdeauthlibrary|--snapshotfolder|\
|
||||
--defaultfrontend)
|
||||
COMPREPLY+=( $(compgen -W "default" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "default" -- ${cur}) )
|
||||
;;
|
||||
|
||||
--vrdeauthtype)
|
||||
COMPREPLY+=( $(compgen -W "null external guest" \
|
||||
COMPREPLY=( $(compgen -W "null external guest" \
|
||||
-- ${cur}) )
|
||||
;;
|
||||
|
||||
@@ -1824,7 +1887,7 @@ _VBoxManage() {
|
||||
COMPREPLY=( $(compgen -W "disabled apic x2apic" \
|
||||
-- ${cur}) )
|
||||
;;
|
||||
--teleporterpasswordfile|--iconfile|--videocapfile)
|
||||
--teleporterpasswordfile|--iconfile|--recordingfile)
|
||||
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||
;;
|
||||
--nictracefile[1-8])
|
||||
@@ -1837,6 +1900,26 @@ _VBoxManage() {
|
||||
fi
|
||||
;;
|
||||
|
||||
movevm)
|
||||
if [[ ${prev} == ${cmd} ]]; then
|
||||
_vms_comp vms
|
||||
else
|
||||
_find_item_name 2
|
||||
items=(--type --folder)
|
||||
_get_excluded_items "${items[@]}"
|
||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||
case "${prev}" in
|
||||
--type)
|
||||
COMPREPLY=( $(compgen -W "basic" -- ${cur}) )
|
||||
_snapshot_comp
|
||||
;;
|
||||
--folder)
|
||||
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
|
||||
natnetwork)
|
||||
items=(add remove modify start stop list)
|
||||
subcommand=${COMP_WORDS[2]}
|
||||
@@ -1889,7 +1972,7 @@ _VBoxManage() {
|
||||
setproperty)
|
||||
items=(machinefolder hwvirtexclusive vrdeauthlibrary
|
||||
websrvauthlibrary vrdeextpack autostartdbpath loghistorycount
|
||||
defaultfrontend logginglevel)
|
||||
defaultfrontend logginglevel proxymode proxyurl)
|
||||
subcommand=${COMP_WORDS[2]}
|
||||
if [[ "${prev}" == "${cmd}" ]]; then
|
||||
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||
@@ -1916,6 +1999,10 @@ _VBoxManage() {
|
||||
defaultfrontend)
|
||||
COMPREPLY=( $(compgen -W "null" -- ${cur}) )
|
||||
;;
|
||||
proxymode)
|
||||
COMPREPLY=( $(compgen -W "system noproxy
|
||||
manual" -- ${cur}) )
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user