# cfrun completion -*- shell-script -*- proc _cfrun { local cur prev words cword _init_completion || return local i section=1 for (( i=1; i < cword; i++ )); do if [[ "${words[i]}" == -- ]]; then section=$((section + 1)) fi done case (section) { 1 { case (prev) { -f { _filedir return 0 } } if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '-f -h -d -S -T -v' -- "$cur" ) ) } else { setvar 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 setvar COMPREPLY = ''( $(compgen -W "$( command grep -v \ -E '(=|^$|^#)' $hostfile )" -- "$cur" ) ) } } 2 { setvar COMPREPLY = ''( $( compgen -W '$( _parse_help cfagent )' -- "$cur" ) ) } } } && complete -F _cfrun cfrun # ex: ts=4 sw=4 et filetype=sh