648606
# bash completion for rpm                                  -*- shell-script -*-
648606
648606
# helper functions
648606
648606
_rpm_installed_packages()
648606
{
648606
    if [[ -r /var/log/rpmpkgs && \
648606
        /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]]; then
648606
        # using RHL 7.2 or later - this is quicker than querying the DB
648606
        COMPREPLY=( $( compgen -W "$( sed -ne \
648606
            's|^\([^[:space:]]\{1,\}\)-[^[:space:]-]\{1,\}-[^[:space:]-]\{1,\}\.rpm$|\1|p' \
648606
            /var/log/rpmpkgs )" -- "$cur" ) )
648606
    elif type rpmqpack &>/dev/null ; then
648606
        # SUSE's rpmqpack is faster than rpm -qa
648606
        COMPREPLY=( $( compgen -W '$( rpmqpack )' -- "$cur" ) )
648606
    else
648606
        COMPREPLY=( $( ${1:-rpm} -qa --nodigest --nosignature \
648606
            --queryformat='%{NAME} ' "$cur*" 2>/dev/null ) )
648606
    fi
648606
}
648606
648606
_rpm_groups()
648606
{
648606
    local IFS=$'\n'
648606
    COMPREPLY=( $( compgen -W "$( ${1:-rpm} -qa --nodigest --nosignature \
648606
        --queryformat='%{GROUP}\n' 2>/dev/null )" -- "$cur" ) )
648606
}
648606
648606
_rpm_macros()
648606
{
648606
    # get a list of macros
648606
    COMPREPLY=( $( compgen -W "$( ${1:-rpm} --showrc | sed -ne \
648606
        's/^-\{0,1\}[0-9]\{1,\}[:=][[:space:]]\{1,\}\([^[:space:](]\{3,\}\).*/%\1/p' )" \
648606
        -- "$cur" ) )
648606
}
648606
648606
_rpm_buildarchs()
648606
{
648606
    COMPREPLY=( $( compgen -W "$( ${1:-rpm} --showrc | sed -ne \
648606
        's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p' )" \
648606
        -- "$cur" ) )
648606
}
648606
648606
# rpm(8) completion
648606
#
648606
_rpm()
648606
{
648606
    local cur prev words cword split
648606
    _init_completion -s || return
648606
648606
    if [[ $cword -eq 1 ]]; then
648606
        # first parameter on line
648606
        case $cur in
648606
            --*)
648606
                COMPREPLY=( $( compgen -W '--help --version --initdb
648606
                    --checksig --addsign --delsign --rebuilddb --showrc
648606
                    --setperms --setugids --eval --install --upgrade --query
648606
                    --freshen --erase --verify --querytags --import' \
648606
                        -- "$cur" ) )
648606
                ;;
648606
            *)
648606
                COMPREPLY=( $( compgen -W '-e -E -F -i -q -t -U -V' \
648606
                    -- "$cur" ) )
648606
                ;;
648606
        esac
648606
        return 0
648606
    fi
648606
648606
    case $prev in
648606
        --dbpath|--excludepath|--prefix|--relocate|--root|-r)
648606
            _filedir -d
648606
            return 0
648606
            ;;
648606
        --eval|-E)
648606
            _rpm_macros $1
648606
            return 0
648606
            ;;
648606
        --pipe)
648606
            compopt -o filenames
648606
            COMPREPLY=( $( compgen -c -- "$cur" ) )
648606
            return 0
648606
            ;;
648606
        --rcfile)
648606
            _filedir
648606
            return 0
648606
            ;;
648606
        --specfile)
648606
            # complete on .spec files
648606
            _filedir spec
648606
            return 0
648606
            ;;
648606
        --whatprovides)
648606
            if [[ "$cur" == */* ]]; then
648606
                _filedir
648606
            else
648606
                # complete on capabilities
648606
                local IFS=$'\n'
648606
                COMPREPLY=( $( compgen -W "$( $1 -qa --nodigest --nosignature \
648606
                    --queryformat='%{PROVIDENAME}\n' 2>/dev/null )" \
648606
                    -- "$cur" ) )
648606
            fi
648606
            return 0
648606
            ;;
648606
        --whatrequires)
648606
            if [[ "$cur" == */* ]]; then
648606
                _filedir
648606
            else
648606
                # complete on capabilities
648606
                local IFS=$'\n'
648606
                COMPREPLY=( $( compgen -W "$( $1 -qa --nodigest --nosignature \
648606
                    --queryformat='%{REQUIRENAME}\n' 2>/dev/null )" \
648606
                    -- "$cur" ) )
648606
            fi
648606
            return 0
648606
            ;;
648606
        --define|-D|--fileid|--hdrid|--pkgid)
648606
            # argument required but no completions available
648606
            return 0
648606
            ;;
648606
    esac
648606
648606
    $split && return 0
648606
648606
    # options common to all modes
648606
    local opts="--define= --eval= --macros= --nodigest --nosignature --rcfile=
648606
        --quiet --pipe --verbose"
648606
648606
    case ${words[1]} in
648606
        -[iFU]*|--install|--freshen|--upgrade)
648606
            if [[ "$cur" == -* ]]; then
648606
                COMPREPLY=( $( compgen -W "$opts --percent --force --test
648606
                --replacepkgs --replacefiles --root --excludedocs --includedocs
648606
                --noscripts --ignorearch --dbpath --prefix= --ignoreos --nodeps
648606
                --allfiles --ftpproxy --ftpport --justdb --httpproxy --httpport
648606
                --noorder --relocate= --badreloc --notriggers --excludepath=
648606
                --ignoresize --oldpackage --queryformat --repackage
648606
                --nosuggests" -- "$cur" ) )
648606
            else
648606
                _filedir '[rs]pm'
648606
            fi
648606
            ;;
648606
        -e|--erase)
648606
            if [[ "$cur" == -* ]]; then
648606
                COMPREPLY=( $( compgen -W "$opts --allmatches --noscripts
648606
                    --notriggers --nodeps --test --repackage" -- "$cur" ) )
648606
            else
648606
                _rpm_installed_packages $1
648606
            fi
648606
            ;;
648606
        -q*|--query)
648606
            # options common to all query types
648606
            opts+=" --changelog --configfiles --conflicts --docfiles --dump
648606
                --enhances --filesbypkg --filecaps --fileclass --filecolor
648606
                --fileprovide --filerequire --filesbypkg --info --list
648606
                --obsoletes --pipe --provides --queryformat= --requires
648606
                --scripts --suggests --triggers --xml"
648606
648606
            if [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then
648606
                # -qf completion
648606
                if [[ "$cur" == -* ]]; then
648606
                    COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext
648606
                        --last --root --state" -- "$cur" ) )
648606
                else
648606
                    _filedir
648606
                fi
648606
            elif [[ ${words[@]} == *\ -@(*([^ -])g|-group )* ]]; then
648606
                # -qg completion
648606
                _rpm_groups $1
648606
            elif [[ ${words[@]} == *\ -@(*([^ -])p|-package )* ]]; then
648606
                # -qp; uninstalled package completion
648606
                if [[ "$cur" == -* ]]; then
648606
                    COMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy
648606
                        --httpport --httpproxy --nomanifest" -- "$cur" ) )
648606
                else
648606
                    _filedir '[rs]pm'
648606
                fi
648606
            else
648606
                # -q; installed package completion
648606
                if [[ "$cur" == -* ]]; then
648606
                    COMPREPLY=( $( compgen -W "$opts --all --file --fileid
648606
                        --dbpath --fscontext --ftswalk --group --hdrid --last
648606
                        --package --pkgid --root= --specfile --state
648606
                        --triggeredby --whatprovides --whatrequires" \
648606
                            -- "$cur" ) )
648606
                elif [[ ${words[@]} != *\ -@(*([^ -])a|-all )* ]]; then
648606
                    _rpm_installed_packages $1
648606
                fi
648606
            fi
648606
            ;;
648606
        -K*|--checksig)
648606
            if [[ "$cur" == -* ]]; then
648606
                COMPREPLY=( $( compgen -W "$opts --nopgp --nogpg --nomd5" \
648606
                    -- "$cur" ) )
648606
            else
648606
                _filedir '[rs]pm'
648606
            fi
648606
            ;;
648606
        -[Vy]*|--verify)
648606
            if [[ "$cur" == -* ]]; then
648606
                COMPREPLY=( $( compgen -W "$opts --root= --dbpath --nodeps
648606
                    --nogroup --nolinkto --nomode --nomtime --nordev --nouser
648606
                    --nofiles --noscripts --nomd5 --querytags --specfile
648606
                    --whatrequires --whatprovides" -- "$cur" ) )
648606
            # check whether we're doing file completion
648606
            elif [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then
648606
                _filedir
648606
            elif [[ ${words[@]} == *\ -@(*([^ -])g|-group )* ]]; then
648606
                _rpm_groups $1
648606
            elif [[ ${words[@]} == *\ -@(*([^ -])p|-package )* ]]; then
648606
                _filedir '[rs]pm'
648606
            else
648606
                _rpm_installed_packages $1
648606
            fi
648606
            ;;
648606
        --resign|--addsign|--delsign)
648606
            _filedir '[rs]pm'
648606
            ;;
648606
        --setperms|--setgids)
648606
            _rpm_installed_packages $1
648606
            ;;
648606
        --import|--dbpath|--root)
648606
            if [[ "$cur" == -* ]]; then
648606
                COMPREPLY=( $( compgen -W '--import --dbpath --root=' \
648606
                    -- "$cur" ) )
648606
            else
648606
                _filedir
648606
            fi
648606
            ;;
648606
    esac
648606
    [[ $COMPREPLY == *= ]] && compopt -o nospace
648606
648606
    return 0
648606
} &&
648606
complete -F _rpm rpm
648606
648606
_rpmbuild()
648606
{
648606
    local cur prev words cword split
648606
    _init_completion -s || return
648606
648606
    local rpm="${1%build*}"
648606
    [[ $rpm == $1 ]] || ! type $rpm &>/dev/null && rpm=
648606
648606
    case $prev in
648606
        --buildroot|--root|-r|--dbpath)
648606
            _filedir -d
648606
            return 0
648606
            ;;
648606
        --target)
648606
            _rpm_buildarchs
648606
            return 0
648606
            ;;
648606
        --eval|-E)
648606
            _rpm_macros $rpm
648606
            return 0
648606
            ;;
648606
        --macros|--rcfile)
648606
            _filedir
648606
            return 0
648606
            ;;
648606
        --buildpolicy)
648606
            local cfgdir=$( $rpm --eval '%{_rpmconfigdir}' 2>/dev/null )
648606
            if [[ $cfgdir ]]; then
648606
                COMPREPLY=( $( compgen -W "$( command ls $cfgdir 2>/dev/null \
648606
                    | sed -ne 's/^brp-//p' )" -- "$cur" ) )
648606
            fi
648606
            ;;
648606
        --define|-D|--with|--without)
648606
            return 0
648606
            ;;
648606
    esac
648606
648606
    $split && return 0
648606
648606
    if [[ $cur == -* ]]; then
648606
        COMPREPLY=( $( compgen -W "$( _parse_help "$1" )" -- "$cur" ) )
648606
        [[ $COMPREPLY == *= ]] && compopt -o nospace
648606
        return 0
648606
    fi
648606
648606
    # Figure out file extensions to complete
648606
    local word ext
648606
    for word in ${words[@]}; do
648606
        case $word in
648606
            -b?)
648606
                ext=spec
648606
                break
648606
                ;;
648606
            -t?|--tarbuild)
648606
                ext='@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
648606
                break
648606
                ;;
648606
            --rebuild|--recompile)
648606
                ext='@(?(no)src.r|s)pm'
648606
                break
648606
                ;;
648606
        esac
648606
    done
648606
    [[ -n $ext ]] && _filedir $ext
648606
} &&
648606
complete -F _rpmbuild rpmbuild rpmbuild-md5
648606
648606
# ex: ts=4 sw=4 et filetype=sh