mirror of
https://github.com/gryf/vboxmanage-bash-completion.git
synced 2025-12-17 11:30:23 +01:00
Another compromise for disk completion, added support for several other commands
This commit is contained in:
198
VBoxManage
198
VBoxManage
@@ -2,12 +2,17 @@
|
|||||||
# development version, or specially used for my opts
|
# development version, or specially used for my opts
|
||||||
# Author: Sebastian T. Hafner <sonix@own-hero.net>
|
# Author: Sebastian T. Hafner <sonix@own-hero.net>
|
||||||
#
|
#
|
||||||
# [ ] adoptstate
|
# This version of bash completion was born due to the need of fast and easy
|
||||||
|
# access to the maze of commands and parameters VBoxManage provides. Based on
|
||||||
|
# Sebastian script I've managed to improve it and adapt to newest stable version
|
||||||
|
# available in Gentoo Portage.
|
||||||
|
#
|
||||||
|
# [x] adoptstate
|
||||||
# [ ] bandwidthctl
|
# [ ] bandwidthctl
|
||||||
# [ ] clonehd
|
# [x] clonehd
|
||||||
# [ ] clonevm
|
# [x] clonevm
|
||||||
# [ ] closemedium
|
# [ ] closemedium
|
||||||
# [ ] controlvm
|
# [x] controlvm
|
||||||
# [ ] convertfromraw
|
# [ ] convertfromraw
|
||||||
# [ ] createhd
|
# [ ] createhd
|
||||||
# [ ] createvm
|
# [ ] createvm
|
||||||
@@ -24,54 +29,54 @@
|
|||||||
# [x] list
|
# [x] list
|
||||||
# [ ] metrics
|
# [ ] metrics
|
||||||
# [ ] modifyhd
|
# [ ] modifyhd
|
||||||
# [ ] modifyvm
|
# [.] modifyvm - a LOT options missing
|
||||||
# [ ] natnetwork
|
# [ ] natnetwork
|
||||||
# [ ] registervm
|
# [ ] registervm
|
||||||
# [ ] setextradata
|
# [ ] setextradata
|
||||||
# [ ] setproperty
|
# [ ] setproperty
|
||||||
# [ ] sharedfolder
|
# [ ] sharedfolder
|
||||||
# [ ] showhdinfo
|
# [x] showhdinfo
|
||||||
# [ ] showvminfo
|
# [x] showvminfo
|
||||||
# [ ] snapshot
|
# [x] snapshot
|
||||||
# [x] startvm
|
# [x] startvm
|
||||||
# [ ] storageattach
|
# [o] storageattach - no all options yet
|
||||||
# [ ] storagectl
|
# [ ] storagectl
|
||||||
# [ ] unregistervm
|
# [x] unregistervm
|
||||||
# [ ] usbfilter
|
# [ ] usbfilter
|
||||||
|
|
||||||
_VBoxManage() {
|
_VBoxManage() {
|
||||||
local cur prev opts vms vms cmd count item
|
local cur prev opts vms vms cmd count item
|
||||||
|
|
||||||
# TODO: This function works quite well with option 'default'. Unfortunately
|
# Generate registered hard disk files.
|
||||||
# there is an issue with filenames which contain space with that setting.
|
# NOTE: This function may introduce some quirks, if there is a space or
|
||||||
# OTOH I don't know how to force bash (or readline) to display full path in
|
# other characters which usually are treated as IFS - like space. Pipe
|
||||||
# possible matches, so there would be a problem with completion of filenames
|
# character used in disk filename will ruin this completions.
|
||||||
# if they are in different place on the fs. After an hour or so of trying to
|
|
||||||
# make it work I just gave up :/
|
|
||||||
_hdcomp() {
|
_hdcomp() {
|
||||||
local cur=$1
|
local cur=$1
|
||||||
local hdds
|
local hdds
|
||||||
|
|
||||||
hdds=$(VBoxManage list hdds | \
|
hdds=$(VBoxManage list hdds | \
|
||||||
|
grep -A 1 'normal (base)' | \
|
||||||
grep "Location:" | \
|
grep "Location:" | \
|
||||||
sed 's/Location:\s\+//' | \
|
sed 's/Location:\s\+//' | \
|
||||||
|
sed 's/\s/\\ /g' | \
|
||||||
tr '\n' '|' | \
|
tr '\n' '|' | \
|
||||||
sed 's/|$//')
|
sed 's/|$//')
|
||||||
IFS='|' read -ra hdds <<< "$hdds"
|
IFS='|' read -ra hdds <<< "$hdds"
|
||||||
|
|
||||||
for item in "${hdds[@]}"
|
for item in "${hdds[@]}"
|
||||||
do
|
do
|
||||||
[[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item") && echo "added hd $item"
|
[[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item")
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Custom function to fill up the COMPREPLY. Works well with spaces in the
|
# Complete registered VM names.
|
||||||
# names of the VMs using option 'filename' for the complete function. Will
|
# Issues are the same as in above function.
|
||||||
# not work if you have a pipe in the VM names. Sorry.
|
|
||||||
_vmscomp() {
|
_vmscomp() {
|
||||||
local cur=$1
|
local cur=$1
|
||||||
local vms
|
local vms
|
||||||
|
|
||||||
|
compopt -o filenames
|
||||||
vms=$(VBoxManage list vms | \
|
vms=$(VBoxManage list vms | \
|
||||||
awk -F ' {' '{ print $1 }' | \
|
awk -F ' {' '{ print $1 }' | \
|
||||||
tr '\n' '|' | \
|
tr '\n' '|' | \
|
||||||
@@ -110,30 +115,39 @@ _VBoxManage() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
case "${prev}" in
|
case "${prev}" in
|
||||||
|
showhdinfo)
|
||||||
# adoptstate)
|
|
||||||
showhdinfo|clonehd)
|
|
||||||
_hdcomp ${cur}
|
_hdcomp ${cur}
|
||||||
;;
|
;;
|
||||||
|
clonevm)
|
||||||
|
_vmscomp ${cur}
|
||||||
|
;;
|
||||||
|
clonehd)
|
||||||
|
case "${cur}" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $(compgen -W "--format --variant
|
||||||
|
--existing" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_hdcomp ${cur}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
--format)
|
--format)
|
||||||
COMPREPLY=( $(compgen -W "VDI VMDK VHD RAW" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "VDI VMDK VHD RAW" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
adoptstate|storageattach|startvm|modifyvm|controlvm|showvminfo|\
|
adoptstate|storageattach|startvm|modifyvm|controlvm|showvminfo|\
|
||||||
unregistervm|vmstatistics|snapshot)
|
unregistervm|snapshot)
|
||||||
_vmscomp ${cur}
|
_vmscomp ${cur}
|
||||||
;;
|
;;
|
||||||
--type) #startvm --type
|
--type) #startvm --type
|
||||||
if [[ ${cmd} == "startvm" ]]; then
|
[[ ${cmd} == "startvm" ]] && \
|
||||||
COMPREPLY=( $(compgen -W "headless vrdp sdl gui" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "headless vrdp sdl gui" -- ${cur}) )
|
||||||
fi
|
[[ ${cmd} == "createhd" ]] && \
|
||||||
if [[ ${cmd} == "createhd" ]]; then
|
|
||||||
COMPREPLY=( $(compgen -W "normal writethrough" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "normal writethrough" -- ${cur}) )
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
--ostype)
|
--ostype)
|
||||||
OS=`VBoxManage list ostypes | grep ID | awk '{ print $2 }'`
|
OS=$(VBoxManage list ostypes | egrep "^ID" | sed "s/ID:\s\+//"|sort)
|
||||||
COMPREPLY=( $(compgen -W "$OS" \
|
COMPREPLY=( $(compgen -W "$OS" -- ${cur}) )
|
||||||
-- ${cur}) )
|
|
||||||
;;
|
;;
|
||||||
--variant)
|
--variant)
|
||||||
COMPREPLY=( $(compgen -W "Standard Fixed Split2G Stream ESX" \
|
COMPREPLY=( $(compgen -W "Standard Fixed Split2G Stream ESX" \
|
||||||
@@ -153,19 +167,16 @@ _VBoxManage() {
|
|||||||
--boot[1-4])
|
--boot[1-4])
|
||||||
COMPREPLY=( $(compgen -W "none floppy dvd disk net" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "none floppy dvd disk net" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
*vrdp)
|
|
||||||
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
|
||||||
;;
|
|
||||||
list)
|
list)
|
||||||
COMPREPLY=( $(compgen -W "vms runningvms ostypes hostdvds
|
t=$(VBoxManage list | \
|
||||||
hostfloppies intnets bridgedifs hostonlyifs natnets dhcpservers
|
grep '|' | \
|
||||||
hostinfo hostcpuids hddbackends hdds dvds floppies usbhost
|
sed 's/\[.*\]//g'| \
|
||||||
usbfilters systemproperties extpacks groups webcams" -- ${cur}) )
|
sed 's/VBoxManage list//' | \
|
||||||
;;
|
tr "\\n" " " | \
|
||||||
# --storageattach
|
sed 's/$/\n/' | \
|
||||||
--storagectl)
|
sed 's/\s\+//g' | \
|
||||||
CONTROLLER="SATA IDE"
|
sed 's/|/ /g')
|
||||||
COMPREPLY=( $(compgen -W "$CONTROLLER" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "$t" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
--device)
|
--device)
|
||||||
COMPREPLY=( $(compgen -W "0" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "0" -- ${cur}) )
|
||||||
@@ -183,13 +194,28 @@ _VBoxManage() {
|
|||||||
done
|
done
|
||||||
_hdcomp ${cur}
|
_hdcomp ${cur}
|
||||||
;;
|
;;
|
||||||
|
--snapshot)
|
||||||
|
;;
|
||||||
--*) #any options ..
|
--*) #any options ..
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
case "${cmd}" in
|
case "${cmd}" in
|
||||||
|
clonevm)
|
||||||
|
case "${prev}" in
|
||||||
|
--mode)
|
||||||
|
COMPREPLY=( $(compgen -W "machine machineandchildren all" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
--options)
|
||||||
|
COMPREPLY=( $(compgen -W "link keepallmacs
|
||||||
|
keepnatmacs keepdisknames" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
COMPREPLY=( $(compgen -W "--snapshot --mode --options
|
||||||
|
--name --groups --basefolder --uuid --register" -- ${cur}) )
|
||||||
|
;;
|
||||||
adoptstate)
|
adoptstate)
|
||||||
COMPREPLY=("dupa")
|
COMPREPLY=()
|
||||||
;;
|
;;
|
||||||
createhd)
|
createhd)
|
||||||
COMPREPLY=( $(compgen -W "--filename --size --type
|
COMPREPLY=( $(compgen -W "--filename --size --type
|
||||||
@@ -200,15 +226,86 @@ _VBoxManage() {
|
|||||||
--basefolder --settingsfile --uid" -- ${cur}) )
|
--basefolder --settingsfile --uid" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
controlvm)
|
controlvm)
|
||||||
COMPREPLY=( $(compgen -W "pause resume poweroff reset
|
case "${prev}" in
|
||||||
savestate acpipowerbutton acpisleepbutton vrdp" -- ${cur}) )
|
nictracefile[0-9]*)
|
||||||
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
|
;;
|
||||||
|
nictrace[0-9]*)
|
||||||
|
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
nicpromisc[0-9]*)
|
||||||
|
COMPREPLY=( $(compgen -W "deny allow-vms
|
||||||
|
allow-all" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
nic[0-9]*)
|
||||||
|
COMPREPLY=( $(compgen -W "null nat bridged intnet
|
||||||
|
hostonly generic natnetwork" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
natpf[0-9]*)
|
||||||
|
COMPREPLY=( $(compgen -W "delete tcp
|
||||||
|
udp" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
clipboard)
|
||||||
|
COMPREPLY=( $(compgen -W "disabled hosttoguest
|
||||||
|
guesttohost bidirectional" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
draganddrop)
|
||||||
|
COMPREPLY=( $(compgen -W "disabled
|
||||||
|
hosttoguest" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
vrde)
|
||||||
|
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
vcpenabled)
|
||||||
|
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
vcpscreens)
|
||||||
|
COMPREPLY=( $(compgen -W "all none" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
setcredentials)
|
||||||
|
COMPREPLY=( $(compgen -W "--passwordfile
|
||||||
|
--allowlocallogon" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
teleport)
|
||||||
|
COMPREPLY=( $(compgen -W "--host --port --maxdowntime
|
||||||
|
--passwordfile --password" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
webcam)
|
||||||
|
COMPREPLY=( $(compgen -W "attach detach
|
||||||
|
list" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
acpipowerbutton|acpisleepbutton|cpuexecutioncap|\
|
||||||
|
guestmemoryballoon|keyboardputscancode|\
|
||||||
|
nicproperty[0-9]*|pause|plugcpu|poweroff|reset|\
|
||||||
|
resume|savestate|screenshotpng|setlinkstate1|\
|
||||||
|
setvideomodehint|unplugcpu|usbattach|usbdetach|\
|
||||||
|
vrdeport|vrdeproperty|vrdevideochannelquality)
|
||||||
|
COMPREPLY=()
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=( $(compgen -W "acpipowerbutton
|
||||||
|
acpisleepbutton clipboard cpuexecutioncap
|
||||||
|
draganddrop guestmemoryballoon keyboardputscancode
|
||||||
|
natpf1 nic1 nicpromisc1 nicproperty1 nictrace1
|
||||||
|
nictracefile1 pause plugcpu poweroff reset resume
|
||||||
|
savestate screenshotpng setcredentials setlinkstate1
|
||||||
|
setvideomodehint teleport unplugcpu usbattach
|
||||||
|
usbdetach vcpenabled vcpscreens vrde vrdeport
|
||||||
|
vrdeproperty vrdevideochannelquality
|
||||||
|
webcam" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
unregistervm)
|
||||||
|
COMPREPLY=( $(compgen -W "--delete" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
startvm)
|
startvm)
|
||||||
COMPREPLY=( $(compgen -W "--type" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "--type" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
snapshot)
|
snapshot)
|
||||||
COMPREPLY=( $(compgen -W "take delete restore restorecurrent
|
COMPREPLY=( $(compgen -W "take delete restore restorecurrent
|
||||||
edit list showvminfo" -- ${cur}) )
|
edit list showvminfo --description --current --name
|
||||||
|
--details --machinereadable" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
modifyvm)
|
modifyvm)
|
||||||
COMPREPLY=( $(compgen -W "--name --memory --ostype --usb
|
COMPREPLY=( $(compgen -W "--name --memory --ostype --usb
|
||||||
@@ -228,6 +325,10 @@ _VBoxManage() {
|
|||||||
COMPREPLY=( $(compgen -W "--storagectl --device --port
|
COMPREPLY=( $(compgen -W "--storagectl --device --port
|
||||||
--medium --type" -- ${cur}) )
|
--medium --type" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
|
showvminfo)
|
||||||
|
COMPREPLY=( $(compgen -W "--details --machinereadable
|
||||||
|
--log" -- ${cur}) )
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
;;
|
;;
|
||||||
@@ -235,7 +336,6 @@ _VBoxManage() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
complete -o filenames -F _VBoxManage VBoxManage
|
complete -o default -F _VBoxManage VBoxManage
|
||||||
#complete -o default -F _VBoxManage VBoxManage
|
|
||||||
|
|
||||||
# vim: set ft=sh tw=80 sw=4 et :
|
# vim: set ft=sh tw=80 sw=4 et :
|
||||||
|
|||||||
Reference in New Issue
Block a user