diff --git a/README b/README index 3d004f6..ddfa9cd 100644 --- a/README +++ b/README @@ -15,6 +15,7 @@ Current version of script was written and tested against VBoxManage in version - controlvm - convertfromraw - createhd +- createvm - list - showhdinfo - showvminfo diff --git a/VBoxManage b/VBoxManage index c605305..844a0dd 100644 --- a/VBoxManage +++ b/VBoxManage @@ -16,7 +16,7 @@ # [x] controlvm # [x] convertfromraw # [x] createhd -# [ ] createvm +# [x] createvm # [ ] debugvm # [ ] dhcpserver # [ ] discardstate @@ -145,6 +145,7 @@ _VBoxManage() { sed 's/|/ /g') COMPREPLY=( $(compgen -W "$list" -- ${cur}) ) } + _group_comp() { local cur=$1 local list @@ -163,6 +164,24 @@ _VBoxManage() { done } + _os_comp() { + local cur=$1 + local list + local item + + list=$(VBoxManage list ostypes | \ + egrep ^ID: | \ + sed 's/ID:\s\+//' | \ + tr '\n' '|' | \ + sed 's/|$//') + IFS='|' read -ra list <<< "$list" + + for item in "${list[@]}" + do + [[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item") + done + } + # Check the COMP_WORDS looking for name of the vm. If name contain space or # is enclosed in quotes, glue name together in variable name. Variable index # will hold the last index of COMP_WORDS array which contain the end of the @@ -582,6 +601,31 @@ _VBoxManage() { fi ;; createvm) + items=(--name --groups --ostype --register --basefolder --uuid) + if [[ ${prev} == ${cmd} ]]; then + COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) ) + else + _get_excluded_items "${items[@]}" + COMPREPLY=( $(compgen -W "$result" -- ${cur}) ) + + case "${prev}" in + --groups) + COMPREPLY=() + _group_comp ${cur} + ;; + --ostype) + COMPREPLY=() + _os_comp ${cur} + ;; + --basefolder) + COMPREPLY=( $(compgen -o dirnames -- ${cur}) ) + ;; + --variant) + COMPREPLY=( $(compgen -W "Standard Fixed Split2G Stream + ESX" -- ${cur}) ) + ;; + esac + fi ;; debugvm) ;;