1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
# bash completion for xm -*- shell-script -*-
_xen_domain_names()
{
COMPREPLY=( $( compgen -W "$( xm list 2>/dev/null | \
awk '!/Name|Domain-0/ { print $1 }' )" -- "$cur" ) )
}
_xen_domain_ids()
{
COMPREPLY=( $( compgen -W "$( xm list 2>/dev/null | \
awk '!/Name|Domain-0/ { print $2 }' )" -- "$cur" ) )
}
_xm()
{
local cur prev words cword
_init_completion || return
# TODO: _split_longopt
local args command commands options
commands='console vncviewer create new delete destroy domid domname
dump-core list mem-max mem-set migrate pause reboot rename reset
restore resume save shutdown start suspend sysrq trigger top unpause
uptime usb-add usb-del vcpu-list vcpu-pin vcpu-set debug-keys dmesg
info log serve sched-credit sched-sedf block-attach block-detach
block-list block-configure network-attach network-detach network-list
vtpm-list pci-attach pci-detach pci-list pci-list-assignable-devices
scsi-attach scsi-detach scsi-list vnet-list vnet-create vnet-delete
labels addlabel rmlabel getlabel dry-run resources dumppolicy setpolicy
resetpolicy getpolicy shell help'
if [[ $cword -eq 1 ]] ; then
COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
else
if [[ "$cur" == *=* ]]; then
prev=${cur/=*/}
cur=${cur/*=/}
fi
command=${words[1]}
if [[ "$cur" == -* ]]; then
# possible options for the command
case $command in
create)
options='-c'
;;
dmesg)
options='--clear'
;;
list)
options='--long'
;;
reboot)
options='-w -a'
;;
shutdown)
options='-w -a -R -H'
;;
sched-credit)
options='-d -w -c'
;;
block-list|network-list|vtpm-list|vnet-list)
options='-l --long'
;;
getpolicy)
options='--dumpxml'
;;
new)
options='-h --help --help_config -q --quiet --path= -f=
--defconfig= -F= --config= -b --dryrun -x --xmldryrun
-s --skipdtd -p --paused -c --console_autoconnect'
;;
esac
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
else
case $command in
console|destroy|domname|domid|list|mem-set|mem-max| \
pause|reboot|rename|shutdown|unpause|vcpu-list|vcpu-pin| \
vcpu-set|block-list|network-list|vtpm-list)
_count_args
case $args in
2)
_xen_domain_names
;;
esac
;;
migrate)
_count_args
case $args in
2)
_xen_domain_names
;;
3)
_known_hosts_real -- "$cur"
;;
esac
;;
restore|dry-run|vnet-create)
_filedir
;;
save)
_count_args
case $args in
2)
_xen_domain_names
;;
3)
_filedir
;;
esac
;;
sysrq)
_count_args
case $args in
2)
_xen_domain_names
;;
3)
COMPREPLY=( $( compgen -W "r s e i u b" \
-- "$cur" ) )
;;
esac
;;
block-attach)
_count_args
case $args in
2)
_xen_domain_names
;;
3)
COMPREPLY=( $( compgen -W "phy: file:" \
-- "$cur" ) )
;;
5)
COMPREPLY=( $( compgen -W "w r" -- "$cur" ) )
;;
6)
_xen_domain_names
;;
esac
;;
block-detach)
_count_args
case $args in
2)
_xen_domain_names
;;
3)
COMPREPLY=( $( compgen -W "$( xm block-list $prev \
2>/dev/null | awk '!/Vdev/ { print $1 }' )" \
-- "$cur" ) )
;;
esac
;;
network-attach)
_count_args
case $args in
2)
_xen_domain_names
;;
*)
COMPREPLY=( $( compgen -W "script= ip= mac= bridge=
backend=" -- "$cur" ) )
;;
esac
;;
network-detach)
_count_args
case $args in
2)
_xen_domain_names
;;
3)
COMPREPLY=( $(compgen -W "$( xm network-list $prev \
2>/dev/null | awk '!/Idx/ { print $1 }' )" \
-- "$cur" ) )
;;
esac
;;
sched-credit)
case $prev in
-d)
_xen_domain_names
return
;;
esac
;;
create)
_filedir
COMPREPLY+=( \
$( compgen -W '$( command ls /etc/xen 2>/dev/null )' \
-- "$cur" ) )
;;
new)
case $prev in
-f|-F|--defconfig|--config)
_filedir
return
;;
--path)
_filedir -d
return
;;
esac
_count_args
case $args in
2)
_xen_domain_names
;;
esac
;;
esac
fi
fi
} &&
complete -F _xm xm
# ex: filetype=sh
|