# cfrun completion -*- shell-script -*- proc _cfrun { var cur = '', prev = '', words = '', cword = '' _init_completion || return var i = '', section = '1' for (( i=1; i < cword; i++ )); do if [[ "${words[i]}" == -- ]]; then section=$((section + 1)) fi done match $section { with 1 match $prev { with -f _filedir return 0 } if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '-f -h -d -S -T -v' -- "$cur" ) ) } else { setglobal hostfile = "$(CFINPUTS:-/var/lib/cfengine/inputs)/cfrun.hosts" for (( i=1; i < cword; i++ )); do if [[ "${words[i]}" == -f ]]; then hostfile=${words[i+1]} break fi done [[ ! -f $hostfile ]] && return 0 setglobal COMPREPLY = '( '$(compgen -W "$( command grep -v \ -E '(=|^$|^#)' $hostfile )" -- "$cur" ) ) } with 2 setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help cfagent )' -- "$cur" ) ) } } && complete -F _cfrun cfrun # ex: ts=4 sw=4 et filetype=sh