# koji completion -*- shell-script -*- proc _koji_search { setglobal COMPREPLY = ''( $( compgen -W \ '$( "$1" -q search $2 "$cur*" 2>/dev/null )' -- "$cur" ) ) } proc _koji_build { _koji_search $1 build } proc _koji_package { _koji_search $1 package } proc _koji_user { _koji_search $1 user } proc _koji_tag { setglobal COMPREPLY = ''( $( compgen -W '$( "$1" -q list-tags 2>/dev/null )' \ -- "$cur" ) ) } proc _koji_target { setglobal COMPREPLY = ''( $( compgen -W '$( "$1" -q list-targets 2>/dev/null | awk "{ print \$1 }" )' -- "$cur" ) ) } proc _koji { local cur prev words cword split _init_completion -s || return local commandix command for (( commandix=1; commandix < cword; commandix++ )); do if [[ ${words[commandix]} != -* ]]; then command=${words[commandix]} break fi done match $prev { with -h|--help|--help-commands return with -c|--config|--keytab|-o _filedir return with --runas|--user|--editor|--by _koji_user $1 return with --authtype setglobal COMPREPLY = ''( $( compgen -W 'noauth ssl password kerberos' \ -- "$cur" ) ) return with --topdir _filedir -d return with --type match $command { with latest-pkg|list-tagged setglobal COMPREPLY = ''( $( compgen -W 'maven' -- "$cur" ) ) } return with --name match $command { with list-targets _koji_target $1 } return with --owner _koji_user $1 return with --tag|--latestfrom _koji_tag $1 return with --package _koji_package $1 return with --build _koji_build $1 return with --build-target _koji_target $1 return } $split && return if [[ $command ]] { if [[ $cur == -* ]] { setglobal COMPREPLY = ''( $( compgen -W \ '$( _parse_help "$1" "$command --help" )' -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace return } # How many'th non-option arg (1-based) for $command are we completing? local i nth=1 for (( i=commandix+1; i < cword; i++ )); do [[ ${words[i]} == -* ]] || (( nth++ )) done match $command { with build|maven-build|win-build match $nth { with 1 _koji_target $1 with 2 _filedir src.rpm } with cancel _koji_build $1 with chain-build match $nth { with 1 _koji_target $1 } with download-build match $nth { with 1 _koji_build $1 } with import-comps match $nth { with 1 _filedir xml with 2 _koji_tag $1 } with latest-by-tag _koji_package $1 with latest-pkg|list-groups|list-tag-inheritance|show-groups match $nth { with 1 _koji_tag $1 } with list-tagged match $nth { with 1 _koji_tag $1 with 2 _koji_package $1 } with list-untagged match $nth { with 1 _koji_package $1 } with move-pkg match $nth { with 1|2 _koji_tag $1 with * _koji_package $1 } with search match $nth { with 1 setglobal COMPREPLY = ''( $( compgen -W 'package build tag target user host rpm' -- "$cur" ) ) } with tag-pkg|untag-pkg match $nth { with 1 _koji_tag $1 with * _koji_package $1 } with taginfo _koji_tag $1 with wait-repo match $nth { with 1 for (( i=commandix+1; i < cword; i++ )); do if [[ ${words[i]} == --target ]]; then _koji_target "$1" return fi done _koji_tag $1 } } return } if [[ $cur == -* ]] { setglobal COMPREPLY = ''( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace } elif [[ ! $command ]] { setglobal COMPREPLY = ''( $( compgen -W '$( "$1" --help-commands 2>/dev/null | \ awk "/^( +|\t)/ { print \$1 }" )' -- "$cur" ) ) } } && complete -F _koji koji arm-koji ppc-koji s390-koji sparc-koji # ex: ts=4 sw=4 et filetype=sh