# bash completion for xm -*- shell-script -*- proc _xen_domain_names { setglobal COMPREPLY = '( '$( compgen -W "$( xm list 2>/dev/null | \ awk '!/Name|Domain-0/ { print $1 }' )" -- "$cur" ) ) } proc _xen_domain_ids { setglobal COMPREPLY = '( '$( compgen -W "$( xm list 2>/dev/null | \ awk '!/Name|Domain-0/ { print $2 }' )" -- "$cur" ) ) } proc _xm { var cur = '', prev = '', words = '', cword = '' _init_completion || return # TODO: _split_longopt var command = '', options = '' setglobal 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 ]] { setglobal COMPREPLY = '( '$( compgen -W "$commands" -- "$cur" ) ) } else { if [[ "$cur" == *=* ]] { set prev = $(cur/=*/) set cur = $(cur/*=/) } set command = $(words[1]) if [[ "$cur" == -* ]] { # possible options for the command match $command { with create set options = ''-c'' with dmesg set options = ''--clear'' with list set options = ''--long'' with reboot set options = ''-w -a'' with shutdown set options = ''-w -a -R -H'' with sched-credit set options = ''-d -w -c'' with block-list|network-list|vtpm-list|vnet-list set options = ''-l --long'' with getpolicy set options = ''--dumpxml'' with new set options = ''-h --help --help_config -q --quiet --path= -f= --defconfig= -F= --config= -b --dryrun -x --xmldryrun -s --skipdtd -p --paused -c --console_autoconnect'' } setglobal COMPREPLY = '( '$( compgen -W "$options" -- "$cur" ) ) } else { match $command { with 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 match $args { with 2 _xen_domain_names } with migrate _count_args match $args { with 2 _xen_domain_names with 3 _known_hosts_real $cur } with restore|dry-run|vnet-create _filedir with save _count_args match $args { with 2 _xen_domain_names with 3 _filedir } with sysrq _count_args match $args { with 2 _xen_domain_names with 3 setglobal COMPREPLY = '( '$( compgen -W "r s e i u b" \ -- "$cur" ) ) } with block-attach _count_args match $args { with 2 _xen_domain_names with 3 setglobal COMPREPLY = '( '$( compgen -W "phy: file:" \ -- "$cur" ) ) with 5 setglobal COMPREPLY = '( '$( compgen -W "w r" -- "$cur" ) ) with 6 _xen_domain_names } with block-detach _count_args match $args { with 2 _xen_domain_names with 3 setglobal COMPREPLY = '( '$( compgen -W "$( xm block-list $prev \ 2>/dev/null | awk '!/Vdev/ { print $1 }' )" \ -- "$cur" ) ) } with network-attach _count_args match $args { with 2 _xen_domain_names with * setglobal COMPREPLY = '( '$( compgen -W "script= ip= mac= bridge= backend=" -- "$cur" ) ) } with network-detach _count_args match $args { with 2 _xen_domain_names with 3 setglobal COMPREPLY = '( '$(compgen -W "$( xm network-list $prev \ 2>/dev/null | awk '!/Idx/ { print $1 }' )" \ -- "$cur" ) ) } with sched-credit match $prev { with -d _xen_domain_names return 0 } with create _filedir setglobal COMPREPLY = '( \ '$( compgen -W '$( command ls /etc/xen 2>/dev/null )' \ -- "$cur" ) ) with new match $prev { with -f|-F|--defconfig|--config _filedir return 0 with --path _filedir -d return 0 } _count_args match $args { with 2 _xen_domain_names } } } } return 0 } && complete -F _xm xm # ex: ts=4 sw=4 et filetype=sh