diff --git a/README b/README index aaa600d..0b41c63 100644 --- a/README +++ b/README @@ -18,6 +18,7 @@ Current version of script was written and tested against VBoxManage in version - createvm - debugvm - dhcpserver +- discardstate - list - showhdinfo - showvminfo diff --git a/VBoxManage b/VBoxManage index 3f35a0f..f4bd9d5 100644 --- a/VBoxManage +++ b/VBoxManage @@ -7,7 +7,6 @@ # # [1] Sebastian T. Hafner # -# [ ] discardstate # [ ] export # [ ] extpack # [ ] getextradata @@ -110,6 +109,28 @@ _VBoxManage() { done } + _vms_state_comp() { + local command=$1 + local cur=$2 + local vms + local item + + compopt -o filenames + + vms=$(VBoxManage list vms -l | \ + egrep '^Name|State' | \ + egrep -B1 'State:\s+saved' | \ + grep Name |sed 's/Name:\s\+//' | \ + tr '\n' '|' | \ + sed 's/|$//' | \ + sed 's/"//g') + IFS='|' read -ra vms <<< "$vms" + for item in "${vms[@]}" + do + [[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item") + done + } + _list_comp() { local cur=$1 local list @@ -348,7 +369,10 @@ _VBoxManage() { case "${cmd}" in adoptstate) - _vms_comp vms ${cur} + _find_item_name 2 + COMPREPLY=() + [[ -z "${name}" ]] && + _vms_state_comp ${cur} ;; bandwidthctl) local items=(add set remove list) @@ -734,6 +758,10 @@ _VBoxManage() { fi ;; discardstate) + _find_item_name 2 + COMPREPLY=() + [[ -z "${name}" ]] && + _vms_state_comp ${cur} ;; "export") ;;