mirror of
https://github.com/gryf/vboxmanage-bash-completion.git
synced 2025-12-19 12:28:19 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 62f57ebbb7 | |||
| d4f56a0d6b | |||
| f8b5981935 | |||
| d027094e7c | |||
| e90270e8ee |
@@ -6,7 +6,7 @@ script. However, in some point of time I've decided to rewrite it almost from
|
|||||||
scratch.
|
scratch.
|
||||||
|
|
||||||
Current version of script was written and tested against VBoxManage in version
|
Current version of script was written and tested against VBoxManage in version
|
||||||
5.1.32, and supports all commands (in some extent ;)).
|
5.2.22, and supports all commands (in some extent ;)).
|
||||||
|
|
||||||
Unlike other attempts, I've tried to make the script context aware. See the
|
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:
|
simple session with the VBoxManage command below, to have an idea how it works:
|
||||||
|
|||||||
145
VBoxManage
145
VBoxManage
@@ -4,7 +4,7 @@
|
|||||||
# URL: https://bitbucket.org/gryf/vboxmanage-bash-completion
|
# URL: https://bitbucket.org/gryf/vboxmanage-bash-completion
|
||||||
# URL: https://github.com/gryf/vboxmanage-bash-completion
|
# URL: https://github.com/gryf/vboxmanage-bash-completion
|
||||||
# License: 3-clause BSD-style license (see LICENSE file)
|
# License: 3-clause BSD-style license (see LICENSE file)
|
||||||
# Version: 5.1.32
|
# Version: 5.2.22
|
||||||
|
|
||||||
_VBoxManage() {
|
_VBoxManage() {
|
||||||
local cur prev opts cmd subcommand tmp items name index result
|
local cur prev opts cmd subcommand tmp items name index result
|
||||||
@@ -42,6 +42,18 @@ _VBoxManage() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_is_any_item_used() {
|
||||||
|
local i
|
||||||
|
|
||||||
|
result=""
|
||||||
|
for i in $@; do
|
||||||
|
if [[ " ${COMP_WORDS[@]} " == *" $i "* ]]; then
|
||||||
|
result="ITIS"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Generate registered hard disk files.
|
# Generate registered hard disk files.
|
||||||
# NOTE: This function may introduce some quirks, if there is a space or
|
# NOTE: This function may introduce some quirks, if there is a space or
|
||||||
# other characters which usually are treated as IFS - like space. Pipe
|
# other characters which usually are treated as IFS - like space. Pipe
|
||||||
@@ -443,7 +455,7 @@ _VBoxManage() {
|
|||||||
|
|
||||||
# add debugvm command manually, since it's described differently in
|
# add debugvm command manually, since it's described differently in
|
||||||
# vboxmanage help
|
# vboxmanage help
|
||||||
opts="${opts} debugvm"
|
opts="${opts} debugvm unattended"
|
||||||
|
|
||||||
if [[ ${cur} == "-q" || ${COMP_CWORD} -eq 1 ]] ; then
|
if [[ ${cur} == "-q" || ${COMP_CWORD} -eq 1 ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||||
@@ -629,14 +641,15 @@ _VBoxManage() {
|
|||||||
vrdevideochannelquality webcam videocap videocapscreens
|
vrdevideochannelquality webcam videocap videocapscreens
|
||||||
videocapfile videocapres videocaprate videocapfps
|
videocapfile videocapres videocaprate videocapfps
|
||||||
videocapmaxtime videocapmaxsize addencpassword removeencpassword
|
videocapmaxtime videocapmaxsize addencpassword removeencpassword
|
||||||
removeallencpasswords)
|
removeallencpasswords keyboardputstring keyboardputfile audioin
|
||||||
|
audioout)
|
||||||
|
|
||||||
_find_item_name 2
|
_find_item_name 2
|
||||||
subcommand=${COMP_WORDS[$((index+1))]}
|
subcommand=${COMP_WORDS[$((index+1))]}
|
||||||
|
|
||||||
if [[ " ${items[@]} " == *" $subcommand "* ]]; then
|
if [[ " ${items[@]} " == *" $subcommand "* ]]; then
|
||||||
case "${subcommand}" in
|
case "${subcommand}" in
|
||||||
nictracefile[1-8])
|
videocapfile|keyboardputfile|nictracefile[1-8])
|
||||||
[[ ${prev} == "nictracefile"* ]] && \
|
[[ ${prev} == "nictracefile"* ]] && \
|
||||||
COMPREPLY=( $(compgen -f -- ${cur}) )
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
@@ -659,7 +672,7 @@ _VBoxManage() {
|
|||||||
COMPREPLY=( $(compgen -W "delete tcp
|
COMPREPLY=( $(compgen -W "delete tcp
|
||||||
udp" -- ${cur}) )
|
udp" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
setlinkstate[1-8])
|
audioin|audioout|setlinkstate[1-8])
|
||||||
[[ ${prev} == "setlinkstate"* ]] && \
|
[[ ${prev} == "setlinkstate"* ]] && \
|
||||||
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
@@ -717,6 +730,8 @@ _VBoxManage() {
|
|||||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
elif [[ ${prev} == "--passwordfile" || ${prev} == "--capturefile" ]]; then
|
||||||
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
else
|
else
|
||||||
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
||||||
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||||
@@ -762,7 +777,7 @@ _VBoxManage() {
|
|||||||
|
|
||||||
case "${prev}" in
|
case "${prev}" in
|
||||||
--filename)
|
--filename)
|
||||||
COMPREPLY=( $(compgen -- ${cur}) )
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
--diffparent)
|
--diffparent)
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
@@ -856,7 +871,7 @@ _VBoxManage() {
|
|||||||
COMPREPLY+=( $(compgen -W "$result" -- ${cur}) )
|
COMPREPLY+=( $(compgen -W "$result" -- ${cur}) )
|
||||||
else
|
else
|
||||||
[[ "${prev}" == "--filename" ]] && \
|
[[ "${prev}" == "--filename" ]] && \
|
||||||
COMPREPLY=( $(compgen -- ${cur}) )
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
||||||
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||||
fi
|
fi
|
||||||
@@ -930,6 +945,8 @@ _VBoxManage() {
|
|||||||
items=( --manifest --iso --options --vsys)
|
items=( --manifest --iso --options --vsys)
|
||||||
if [[ ${prev} == ${cmd} ]]; then
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
_vms_comp vms
|
_vms_comp vms
|
||||||
|
elif [[ ${prev} == "--eulafile" ]]; then
|
||||||
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
else
|
else
|
||||||
[[ " ${COMP_WORDS[@]} " != *" -o "* &&
|
[[ " ${COMP_WORDS[@]} " != *" -o "* &&
|
||||||
" ${COMP_WORDS[@]} " != *" --output "* ]] &&
|
" ${COMP_WORDS[@]} " != *" --output "* ]] &&
|
||||||
@@ -937,8 +954,9 @@ _VBoxManage() {
|
|||||||
[[ " ${COMP_WORDS[@]} " != *" --legacy09 "* &&
|
[[ " ${COMP_WORDS[@]} " != *" --legacy09 "* &&
|
||||||
" ${COMP_WORDS[@]} " != *" --ovf09 "* &&
|
" ${COMP_WORDS[@]} " != *" --ovf09 "* &&
|
||||||
" ${COMP_WORDS[@]} " != *" --ovf10 "* &&
|
" ${COMP_WORDS[@]} " != *" --ovf10 "* &&
|
||||||
" ${COMP_WORDS[@]} " != *" --ovf20 "* ]] &&
|
" ${COMP_WORDS[@]} " != *" --ovf20 "* &&
|
||||||
items+=(--legacy09 --ovf09 --ovf10 --ovf20)
|
" ${COMP_WORDS[@]} " != *" --opc20 "* ]] &&
|
||||||
|
items+=(--legacy09 --ovf09 --ovf10 --ovf20 --opc10)
|
||||||
[[ " ${COMP_WORDS[@]} " == *" --vsys "* ]] &&
|
[[ " ${COMP_WORDS[@]} " == *" --vsys "* ]] &&
|
||||||
items+=(--product --producturl --vendor --vendorurl
|
items+=(--product --producturl --vendor --vendorurl
|
||||||
--version --description --eula --eulafile)
|
--version --description --eula --eulafile)
|
||||||
@@ -951,8 +969,8 @@ _VBoxManage() {
|
|||||||
nomacsbutnat" -- ${cur}) )
|
nomacsbutnat" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
||||||
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -1288,7 +1306,7 @@ _VBoxManage() {
|
|||||||
--image)
|
--image)
|
||||||
COMPREPLY=( $(compgen -- ${cur}) )
|
COMPREPLY=( $(compgen -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
--tmpdir)
|
--target-directory|--tmpdir)
|
||||||
COMPREPLY=( $(compgen -o dirnames -- ${cur}) )
|
COMPREPLY=( $(compgen -o dirnames -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
--source)
|
--source)
|
||||||
@@ -1299,6 +1317,9 @@ _VBoxManage() {
|
|||||||
"${COMPREPLY[0]}" != *".iso" ]] && \
|
"${COMPREPLY[0]}" != *".iso" ]] && \
|
||||||
COMPREPLY[0]="${COMPREPLY[0]}/"
|
COMPREPLY[0]="${COMPREPLY[0]}/"
|
||||||
;;
|
;;
|
||||||
|
--passwordfile)
|
||||||
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
|
||||||
@@ -1401,11 +1422,14 @@ _VBoxManage() {
|
|||||||
_list_comp ${cur}
|
_list_comp ${cur}
|
||||||
else
|
else
|
||||||
case "${prev}" in
|
case "${prev}" in
|
||||||
|
--sorted|-s)
|
||||||
|
COMPREPLY=( $(compgen -W "-l --long" -- ${cur}) )
|
||||||
|
;;
|
||||||
--long|-l)
|
--long|-l)
|
||||||
COMPREPLY=()
|
COMPREPLY=( $(compgen -W "-s --sorted" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
COMPREPLY=( $(compgen -W "-l --long" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "-l --long -s --sorted" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
@@ -1498,7 +1522,7 @@ _VBoxManage() {
|
|||||||
*)
|
*)
|
||||||
_find_item_name 2
|
_find_item_name 2
|
||||||
items=(--type --autoreset --property --compact --resize
|
items=(--type --autoreset --property --compact --resize
|
||||||
--move)
|
--move --description)
|
||||||
_get_excluded_items "${items[@]}"
|
_get_excluded_items "${items[@]}"
|
||||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||||
case "${prev}" in
|
case "${prev}" in
|
||||||
@@ -1523,7 +1547,7 @@ _VBoxManage() {
|
|||||||
items=(--name --groups --description --ostype --iconfile --memory
|
items=(--name --groups --description --ostype --iconfile --memory
|
||||||
--pagefusion --vram --acpi --pciattach --pcidetach --ioapic --hpet
|
--pagefusion --vram --acpi --pciattach --pcidetach --ioapic --hpet
|
||||||
--triplefaultreset --hwvirtex --nestedpaging --largepages --vtxvpid
|
--triplefaultreset --hwvirtex --nestedpaging --largepages --vtxvpid
|
||||||
--vtxux --pae --longmode --cpuidset --cpuidremove
|
--vtxux --pae --longmode --cpuid-set --cpuid-remove
|
||||||
--cpuidremoveall --hardwareuuid --cpus --cpuhotplug --plugcpu
|
--cpuidremoveall --hardwareuuid --cpus --cpuhotplug --plugcpu
|
||||||
--unplugcpu --cpuexecutioncap --rtcuseutc --graphicscontroller
|
--unplugcpu --cpuexecutioncap --rtcuseutc --graphicscontroller
|
||||||
--monitorcount --accelerate3d --accelerate2dvideo --firmware
|
--monitorcount --accelerate3d --accelerate2dvideo --firmware
|
||||||
@@ -1592,7 +1616,9 @@ _VBoxManage() {
|
|||||||
--videocapmaxtime --videocapmaxsize --videocapopts --defaultfrontend
|
--videocapmaxtime --videocapmaxsize --videocapopts --defaultfrontend
|
||||||
--cpuid-portability-level --paravirtprovider --audiocodec --usbxhci
|
--cpuid-portability-level --paravirtprovider --audiocodec --usbxhci
|
||||||
--usbrename --apic --x2apic --paravirtdebug --cpu-profile
|
--usbrename --apic --x2apic --paravirtdebug --cpu-profile
|
||||||
--biosapic --videocapopts --ibpb-on-vm-entry --ibpb-on-vm-exit)
|
--biosapic --videocapopts --ibpb-on-vm-entry --ibpb-on-vm-exit
|
||||||
|
--spec-ctrl --audioin --audioout --l1d-flush-on-sched
|
||||||
|
--l1d-flush-on-vm-entry)
|
||||||
|
|
||||||
if [[ ${prev} == ${cmd} ]]; then
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
_vms_comp vms
|
_vms_comp vms
|
||||||
@@ -1632,7 +1658,8 @@ _VBoxManage() {
|
|||||||
--usbehci|--teleporter|--tracing-enabled|\
|
--usbehci|--teleporter|--tracing-enabled|\
|
||||||
--tracing-allow-vm-access|--usbcardreader|\
|
--tracing-allow-vm-access|--usbcardreader|\
|
||||||
--autostart-enabled|--videocap|--usbxhci|--apic|--x2apic|\
|
--autostart-enabled|--videocap|--usbxhci|--apic|--x2apic|\
|
||||||
--ibpb-on-vm-entry|--ibpb-on-vm-exit)
|
--ibpb-on-vm-entry|--ibpb-on-vm-exit|--spec-ctrl|--audioin|\
|
||||||
|
--audioout|--l1d-flush-on-sched|--l1d-flush-on-vm-entry)
|
||||||
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -1793,6 +1820,15 @@ _VBoxManage() {
|
|||||||
COMPREPLY=( $(compgen -W "disabled apic x2apic" \
|
COMPREPLY=( $(compgen -W "disabled apic x2apic" \
|
||||||
-- ${cur}) )
|
-- ${cur}) )
|
||||||
;;
|
;;
|
||||||
|
--teleporterpasswordfile|--iconfile|--videocapfile)
|
||||||
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
|
;;
|
||||||
|
--nictracefile[1-8])
|
||||||
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
|
;;
|
||||||
|
--nattftpfile[1-8])
|
||||||
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -2012,7 +2048,13 @@ _VBoxManage() {
|
|||||||
elif [[ "${prev}" == "--type" ]]; then
|
elif [[ "${prev}" == "--type" ]]; then
|
||||||
COMPREPLY=( $(compgen -W "gui sdl headless separate" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "gui sdl headless separate" -- ${cur}) )
|
||||||
else
|
else
|
||||||
local items=(--type)
|
local items=(--putenv -E)
|
||||||
|
_is_any_item_used "${items[@]}"
|
||||||
|
if [[ "${result}" == "ITIS" ]]; then
|
||||||
|
local items=(--type)
|
||||||
|
else
|
||||||
|
local items=(--type -E --putenv)
|
||||||
|
fi
|
||||||
_get_excluded_items "${items[@]}"
|
_get_excluded_items "${items[@]}"
|
||||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||||
fi
|
fi
|
||||||
@@ -2027,7 +2069,7 @@ _VBoxManage() {
|
|||||||
--comment --setuuid --setparentuuid --passthrough --tempeject
|
--comment --setuuid --setparentuuid --passthrough --tempeject
|
||||||
--nonrotational --discard --hotpluggable --bandwidthgroup
|
--nonrotational --discard --hotpluggable --bandwidthgroup
|
||||||
--forceunmount --server --target --tport --lun --encodedlun
|
--forceunmount --server --target --tport --lun --encodedlun
|
||||||
--username --password --initiator --intnet)
|
--username --password --initiator --intnet --passwordfile)
|
||||||
_get_excluded_items "${items[@]}"
|
_get_excluded_items "${items[@]}"
|
||||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||||
|
|
||||||
@@ -2053,6 +2095,9 @@ _VBoxManage() {
|
|||||||
--passthrough|--tempeject|--nonrotational|--discard)
|
--passthrough|--tempeject|--nonrotational|--discard)
|
||||||
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "on off" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
|
--passwordfile)
|
||||||
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -2155,6 +2200,66 @@ _VBoxManage() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
unattended)
|
||||||
|
if [[ COMP_CWORD -ge 3 ]]; then
|
||||||
|
subcommand="${COMP_WORDS[2]}"
|
||||||
|
if [[ $subcommand == "${cmd}" ]]; then
|
||||||
|
subcommand="${COMP_WORDS[3]}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
|
COMPREPLY=( $(compgen -W "detect install" -- ${cur}) )
|
||||||
|
else
|
||||||
|
case "${prev}" in
|
||||||
|
--iso|--password-file|--additions-iso|--validation-kit-iso|\
|
||||||
|
--script-template|--post-install-template)
|
||||||
|
COMPREPLY+=( $(compgen -f -- ${cur}) )
|
||||||
|
;;
|
||||||
|
--auxiliary-base-path)
|
||||||
|
COMPREPLY+=( $(compgen -o dirnames -- ${cur}) )
|
||||||
|
;;
|
||||||
|
--start-vm)
|
||||||
|
COMPREPLY=( $(compgen -W "gui sdl headless separate" \
|
||||||
|
-- ${cur}) )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
|
||||||
|
case "${subcommand}" in
|
||||||
|
detect)
|
||||||
|
local items=(--iso --machine-readable)
|
||||||
|
_get_excluded_items "${items[@]}"
|
||||||
|
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||||
|
;;
|
||||||
|
install)
|
||||||
|
if [[ ${prev} == ${subcommand} ]]; then
|
||||||
|
_vms_comp vms
|
||||||
|
else
|
||||||
|
local items=(--iso --user=login
|
||||||
|
--password=password --password-file
|
||||||
|
--full-user-name --key
|
||||||
|
--install-additions --no-install-additions
|
||||||
|
--additions-iso --install-txs --no-install-txs
|
||||||
|
--validation-kit-iso --locale --country
|
||||||
|
--time-zone --hostname
|
||||||
|
--package-selection-adjustment --dry-run
|
||||||
|
--auxiliary-base-path=path --image-index
|
||||||
|
--script-template --post-install-template
|
||||||
|
--post-install-command
|
||||||
|
--extra-install-kernel-parameters --language
|
||||||
|
--start-vm)
|
||||||
|
_get_excluded_items "${items[@]}"
|
||||||
|
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
complete -o default -F _VBoxManage VBoxManage
|
complete -o default -F _VBoxManage VBoxManage
|
||||||
|
|||||||
Reference in New Issue
Block a user