# bash completion for quickpkg
#
# Tony Williams, honestpuck@gmail.completion
# v1.0 2020-03-24

_quickpkg() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    opts="--ownership --output --clean --no-clean --relocatable --no-relocatable \
        --sign --keychain --cert --verbosity --version --help"

    own="recommended preserve preserve-other"

    if [ $prev == "--ownership" ] ; then
        COMPREPLY=($(compgen -W "$own" - "$cur"))
        return
    fi

    if [ $prev == "--keychain" ] ; then
        local keychains="$(security list-keychains)"
        COMPREPLY=($(compgen -W "$keychains" -- "$cur"))
        return
    fi

    case "$cur" in
    -*)
        COMPREPLY=($(compgen -W "$opts" - "$cur"))
        return
        ;;
    esac
}

complete -o bashdefault -o default -F _quickpkg quickpkg
