Blame | Last modification | View Log | RSS feed
# bash completion for rpmhave rpm && {# helper functions_rpm_installed_packages(){local nodig="$1" nosig="$2"if [[ -r /var/log/rpmpkgs && \/var/log/rpmpkgs -nt /var/lib/rpm/Packages ]]; then# using RHL 7.2 or later - this is quicker than querying the DBCOMPREPLY=( $( compgen -W "$( sed -ne \'s|^\([^[:space:]]\{1,\}\)-[^[:space:]-]\{1,\}-[^[:space:]-]\{1,\}\.rpm$|\1|p' \/var/log/rpmpkgs )" -- "$cur" ) )elif type rpmqpack &>/dev/null ; then# SUSE's rpmqpack is faster than rpm -qaCOMPREPLY=( $( compgen -W '$( rpmqpack )' -- "$cur" ) )else_rpm_nodigsigCOMPREPLY=( $( rpm -qa $nodig $nosig --qf='%{NAME} ' "$cur*" ) )fi}_rpm_groups(){local IFS=$'\n'COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig --queryformat \'%{group}\n' )" -- "$cur" ) )}_rpm_nodigsig(){if [[ -z "$nodig" && -z "$nosig" ]]; thenlocal rpmverrpmver=$(rpm --version)rpmver=${rpmver##* }if [[ "$rpmver" > "4.0.4" ]]; thennodig="--nodigest"fiif [[ "$rpmver" > "4.0.99" ]]; thennosig="--nosignature"fifi}# rpm(8) completion#_rpm(){local cur prev opts nodig nosigCOMPREPLY=()_get_comp_words_by_ref cur prevnodig=""nosig=""_rpm_nodigsigif [ $COMP_CWORD -eq 1 ]; then# first parameter on linecase $cur in-b*)COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs' \-- "$cur" ) );;-t*)COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts' \-- "$cur" ) );;--*)COMPREPLY=( $( compgen -W '--help --version --initdb \--checksig --recompile --rebuild --resign --addsign \--rebuilddb --showrc --setperms --setugids --tarbuild \--eval --install --upgrade --query --freshen --erase \--verify --querytags --rmsource --rmspec --clean \--import' -- "$cur" ) );;*)COMPREPLY=( $( compgen -W '-b -e -E -F -i -q -t -U -V' \-- "$cur" ) );;esacreturn 0ficase $prev in--dbpath|--excludepath|--prefix|--relocate|--root)_filedir -dreturn 0;;--eval|-E)# get a list of macrosCOMPREPLY=( $( compgen -W "$( rpm --showrc | sed -ne \'s/^-\{0,1\}[0-9]\{1,\}[:=][[:space:]]\{1,\}\([^[:space:](]\{3,\}\).*/%\1/p' )" \-- "$cur" ) )return 0;;--pipe)_compopt_o_filenamesCOMPREPLY=( $( compgen -c -- "$cur" ) )return 0;;--rcfile)_filedirreturn 0;;--specfile)# complete on .spec files_filedir specreturn 0;;--whatprovides)if [[ "$cur" == */* ]]; then_filedirelse# complete on capabilitieslocal IFS=$'\n'COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig \--queryformat='%{providename}\n' )" -- "$cur" ) )fireturn 0;;--whatrequires)if [[ "$cur" == */* ]]; then_filedirelse# complete on capabilitieslocal IFS=$'\n'COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig \--queryformat='%{requirename}\n' )" -- "$cur" ) )fireturn 0;;--target)COMPREPLY=( $( compgen -W "$( command rpm --showrc | sed -ne \'s/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p' )" \-- "$cur" ) )return 0;;--define|-D|--fileid|--hdrid|--pkgid)# argument required but no completions availablereturn 0;;esac# options common to all modesopts="--define --eval --macros --nodigest --nosignature --rcfile \--quiet --pipe --verbose"case ${COMP_WORDS[1]} in-[iFU]*|--install|--freshen|--upgrade)if [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --percent --force \--test --replacepkgs --replacefiles --root \--excludedocs --includedocs --noscripts --ignorearch \--dbpath --prefix --ignoreos --nodeps --allfiles \--ftpproxy --ftpport --justdb --httpproxy --httpport \--noorder --relocate --badreloc --notriggers \--excludepath --ignoresize --oldpackage \--queryformat --repackage --nosuggests" -- "$cur" ) )else_filedir '[rs]pm'fi;;-e|--erase)if [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --allmatches \--noscripts --notriggers --nodeps --test --repackage" \-- "$cur" ) )else_rpm_installed_packages "$nodig" "$nosig"fi;;-q*|--query)# options common to all query typesopts="$opts --changelog --configfiles --conflicts --docfiles--dump --enhances --filesbypkg --filecaps --fileclass--filecolor --fileprovide --filerequire --filesbypkg --info--list --obsoletes --pipe --provides --queryformat --rcfile--requires --scripts --suggests --triggers --xml"if [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then# -qf completionif [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \--last --root --state" -- "$cur" ) )else_filedirfielif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then# -qg completion_rpm_groupselif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then# -qp; uninstalled package completionif [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy \--httpport --httpproxy --nomanifest" -- "$cur" ) )else_filedir '[rs]pm'fielse# -q; installed package completionif [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --all --file --fileid--dbpath --fscontext --ftswalk --group --hdrid --last--package --pkgid --root --specfile --state--triggeredby --whatprovides --whatrequires" \-- "$cur" ) )elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then_rpm_installed_packages "$nodig" "$nosig"fifi;;-K*|--checksig)if [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --nopgp --nogpg --nomd5" \-- "$cur" ) )else_filedir '[rs]pm'fi;;-[Vy]*|--verify)if [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --root --dbpath --nodeps \--nogroup --nolinkto --nomode --nomtime --nordev --nouser \--nofiles --noscripts --nomd5 --querytags --specfile \--whatrequires --whatprovides" -- "$cur" ) )# check whether we're doing file completionelif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then_filedirelif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then_rpm_groupselif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then_filedir '[rs]pm'else_rpm_installed_packages "$nodig" "$nosig"fi;;-[bt]*)if [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --short-circuit --timecheck \--clean --rmsource --rmspec --test --sign --buildroot \--target --nobuild --nodeps --nodirtokens" -- "$cur" ) )elif [[ ${COMP_WORDS[1]} == -b* ]]; then_filedir specelse_filedir '@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'fi;;--rebuild|--recompile)if [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W "$opts --nodeps --rmsource \--rmspec --sign --nodirtokens --target" -- "$cur" ) )else_filedir '@(?(no)src.r|s)pm'fi;;--tarbuild)_filedir '@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))';;--resign|--addsign)_filedir '[rs]pm';;--setperms|--setgids)_rpm_installed_packages "$nodig" "$nosig";;--clean|--rmsource|--rmspec)if [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W '--clean --rmsource --rmspec' \-- "$cur" ) )else_filedir specfi;;--import|--dbpath|--root)if [[ "$cur" == -* ]]; thenCOMPREPLY=( $( compgen -W '--import --dbpath --root' \-- "$cur" ) )else_filedirfi;;esacreturn 0}complete -F _rpm rpm rpmbuild}have gendiff &&_gendiff(){COMPREPLY=()local cur prev cword_get_comp_words_by_ref cur prev cwordif [[ $cword -eq 1 ]]; then_filedir -delif [[ $prev == *\> ]]; then_filedirfi} &&complete -F _gendiff gendiff# Local variables:# mode: shell-script# sh-basic-offset: 4# sh-indent-comment: t# indent-tabs-mode: nil# End:# ex: ts=4 sw=4 et filetype=sh