Created
May 3, 2018 09:09
-
-
Save jlevon/b3c306a408ffc0430ccdf73a5503c1f7 to your computer and use it in GitHub Desktop.
vmadm alias completion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
]] && [[ ${COMP_WORDS[COMP_CWORD-2]} == "vmadm" ]]; then | |
vms_uuids=$(zoneadm list -cp | grep -v ':global:' | cut -d':' -f5 | \ | |
sort | uniq) | |
vms_aliases=$(vmadm list -Ho alias | sort -u) | |
gen=$(compgen -W "${vms_aliases}" -- ${cur}) | |
if [ "$(echo $gen | wc -w)" -eq 1 ]; then | |
COMPREPLY=$(vmadm list -Ho uuid alias=$gen) | |
else | |
COMPREPLY=( $(compgen -W "${vms_uuids} ${vms_aliases}" -- ${cur}) ) | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can get rid of wc by using an array.
This also has issues with multiple zones having the same alias and aliases with spaces (assuming that's a thing).