# bash completion for xm # $Id: xen 444 2008-03-22 14:23:10Z guillomovitch $ _xm() { local cur prev command options COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} commands='console create destroy domid domname list mem-max mem-set \ migrate pause reboot rename restore save shutdown sysrq top \ unpause vcpu-list vcpu-pin vcpu-set dmesg info log top \ sched-bvt sched-bvt-ctxallow sched-sedf block-attach \ block-detach block-list network-attach network-detach \ network-list nvet-kist vnet-create vnet-delete help' if [[ $COMP_CWORD -eq 1 ]] ; then COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) else command=${COMP_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' ;; esac COMPREPLY=( $( compgen -W "$options" -- $cur ) ) else case $command in help) COMPREPLY=( $(compgen -W "$commands" -- $cur) ) ;; @(console|destroy|domnamde|list|mem-@(set|max)|migrate|pause|reboot|rename|save|shutdown|sysrq|unpause|vcpu-@(list|pin|set)|block-@(attach|detach|list)|network-@(attach|detach|list))) # complete on dom ID COMPREPLY=( $(compgen -W "$( xm list | awk '{ print $1 }' | grep -v -e Name -e Domain-0 )" -- $cur) ) ;; create) _filedir COMPREPLY=( ${COMPREPLY[@]:-} \ $( command ls /etc/xen | grep "^$cur" ) ) ;; esac fi fi return 0 } complete -F _xm xm