mirror of
https://github.com/gryf/vboxmanage-bash-completion.git
synced 2025-12-17 03:20:20 +01:00
Make startvm command complete only not running vms
This commit is contained in:
31
VBoxManage
31
VBoxManage
@@ -102,10 +102,24 @@ _VBoxManage() {
|
||||
# Issues are the same as in above function.
|
||||
_vms_comp() {
|
||||
local command=$1
|
||||
local exclude_running=false
|
||||
local vms
|
||||
local running_vms
|
||||
local item
|
||||
|
||||
|
||||
compopt -o filenames
|
||||
if [[ $# == 2 ]]
|
||||
then
|
||||
exclude_running=true
|
||||
running_vms=$(VBoxManage list runningvms | \
|
||||
awk -F ' {' '{ print $1 }' | \
|
||||
tr '\n' '|' | \
|
||||
sed 's/|$//' | \
|
||||
sed 's/"//g')
|
||||
IFS='|' read -ra running_vms <<< "$running_vms"
|
||||
fi
|
||||
|
||||
vms=$(VBoxManage list $command | \
|
||||
awk -F ' {' '{ print $1 }' | \
|
||||
tr '\n' '|' | \
|
||||
@@ -114,6 +128,12 @@ _VBoxManage() {
|
||||
IFS='|' read -ra vms <<< "$vms"
|
||||
for item in "${vms[@]}"
|
||||
do
|
||||
if $exclude_running
|
||||
then
|
||||
_is_in_array "$item" "${running_vms[@]}"
|
||||
[[ $? == 0 ]] && continue
|
||||
fi
|
||||
|
||||
[[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item")
|
||||
done
|
||||
}
|
||||
@@ -370,6 +390,15 @@ _VBoxManage() {
|
||||
done
|
||||
}
|
||||
|
||||
_is_in_array() {
|
||||
local element
|
||||
for element in "${@:2}"
|
||||
do
|
||||
[[ "$element" == "$1" ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
COMP_WORDBREAKS=${COMP_WORDBREAKS//|/} # remove pipe from comp word breaks
|
||||
COMPREPLY=()
|
||||
@@ -1605,7 +1634,7 @@ _VBoxManage() {
|
||||
;;
|
||||
startvm)
|
||||
if [[ ${prev} == ${cmd} ]]; then
|
||||
_vms_comp vms
|
||||
_vms_comp vms 1
|
||||
elif [[ "${prev}" == "--type" ]]; then
|
||||
COMPREPLY=( $(compgen -W "gui sdl headless" -- ${cur}) )
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user