# PLD Linux builder(1) script completion # get active spec file from commandline # caller should make $spec local variable # TODO: it gets it wrong if some option arg is found before spec itself _builder_get_spec() { local i spec= for (( i=1; i < ${#words[@]}-1; i++ )); do if [[ ${words[i]} != -* ]]; then spec=${words[i]} break fi done [[ ! -f $spec ]] && return 0 } _builder() { local cur prev words cword _init_completion || return case $prev in -r) COMPREPLY=( $( compgen -W '$( git tag )' -- "$cur" ) ) return 0 ;; --with|--without) local spec bconds _builder_get_spec bconds=$( awk ' /^%changelog/ { exit } /^%bcond_with/{ print $2 }' $spec ) COMPREPLY=( $( compgen -W "$bconds" -- "$cur" ) ) return 0 ;; esac if [[ $cur == -* ]]; then COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) else _filedir spec fi } && complete -F _builder builder