admin-trinkets/hopon/010_hopon_completion.bash

23 lines
540 B
Bash
Raw Normal View History

2024-07-12 15:47:23 +00:00
#/usr/bin/env bash
_hopon_completions () {
# Check to see if a container/VM manager is installed.
local vm_manager=""
2024-07-12 16:15:24 +00:00
if [ -x "$(command -v incus)" ]; then
2024-07-12 15:47:23 +00:00
vm_manager="incus"
2024-07-12 16:15:24 +00:00
elif [ -x "$(command -v lxc)" ]; then
vm_manager="lxc"
2024-07-12 15:47:23 +00:00
else
return
fi
# We only want one copy of the found parameter.
if [ "${#COMP_WORDS[@]}" != "2" ]; then
return
fi
COMPREPLY=($(compgen -W "$($vm_manager list -c n -f csv)" -- "${COMP_WORDS[1]}"))
}
complete -F _hopon_completions hopon