home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / rpm < prev    next >
Encoding:
Text File  |  2010-11-16  |  10.0 KB  |  300 lines

  1. # bash completion for rpm
  2.  
  3. have rpm && {
  4. # helper functions
  5.  
  6. _rpm_installed_packages()
  7. {
  8.     local nodig="$1" nosig="$2"
  9.  
  10.     if [[ -r /var/log/rpmpkgs && \
  11.         /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]]; then
  12.         # using RHL 7.2 or later - this is quicker than querying the DB
  13.         COMPREPLY=( $( compgen -W "$( sed -ne \
  14.             's|^\([^[:space:]]\{1,\}\)-[^[:space:]-]\{1,\}-[^[:space:]-]\{1,\}\.rpm$|\1|p' \
  15.             /var/log/rpmpkgs )" -- "$cur" ) )
  16.     elif type rpmqpack &>/dev/null ; then
  17.         # SUSE's rpmqpack is faster than rpm -qa
  18.         COMPREPLY=( $( compgen -W '$( rpmqpack )' -- "$cur" ) )
  19.     else
  20.         _rpm_nodigsig
  21.         COMPREPLY=( $( rpm -qa $nodig $nosig --qf='%{NAME} ' "$cur*" ) )
  22.     fi
  23. }
  24.  
  25. _rpm_groups()
  26. {
  27.     # TODO: shown completions are wrong but real ones work nevertheless
  28.     # http://lists.alioth.debian.org/pipermail/bash-completion-devel/2009-May/001486.html
  29.     local IFS=$'\n'
  30.     COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig --queryformat \
  31.         '%{group}\n' )" -- "$cur" ) )
  32. }
  33.  
  34. _rpm_nodigsig()
  35. {
  36.     if [[ -z "$nodig" && -z "$nosig" ]]; then
  37.         local rpmver
  38.  
  39.         rpmver=$(rpm --version)
  40.         rpmver=${rpmver##* }
  41.  
  42.         if [[ "$rpmver" > "4.0.4" ]]; then
  43.             nodig="--nodigest"
  44.         fi
  45.         if [[ "$rpmver" > "4.0.99" ]]; then
  46.             nosig="--nosignature"
  47.         fi
  48.     fi
  49. }
  50.  
  51. # rpm(8) completion
  52. #
  53. _rpm()
  54. {
  55.     local cur prev opts nodig nosig
  56.  
  57.     COMPREPLY=()
  58.     _get_comp_words_by_ref cur prev
  59.     nodig=""
  60.     nosig=""
  61.     _rpm_nodigsig
  62.  
  63.     if [ $COMP_CWORD -eq 1 ]; then
  64.         # first parameter on line
  65.         case $cur in
  66.             -b*)
  67.                 COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs' \
  68.                     -- "$cur" ) )
  69.                 ;;
  70.             -t*)
  71.                 COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts' \
  72.                     -- "$cur" ) )
  73.                 ;;
  74.             --*)
  75.                 COMPREPLY=( $( compgen -W '--help --version --initdb \
  76.                     --checksig --recompile --rebuild --resign --addsign \
  77.                     --rebuilddb --showrc --setperms --setugids --tarbuild \
  78.                     --eval --install --upgrade --query --freshen --erase \
  79.                     --verify --querytags --rmsource --rmspec --clean \
  80.                     --import' -- "$cur" ) )
  81.                 ;;
  82.             *)
  83.                 COMPREPLY=( $( compgen -W '-b -e -E -F -i -q -t -U -V' \
  84.                     -- "$cur" ) )
  85.                 ;;
  86.         esac
  87.  
  88.     return 0
  89.     fi
  90.  
  91.     case $prev in
  92.         --dbpath|--excludepath|--prefix|--relocate|--root)
  93.             _filedir -d
  94.             return 0
  95.             ;;
  96.         --eval|-E)
  97.             # get a list of macros
  98.             COMPREPLY=( $( compgen -W "$( rpm --showrc | sed -ne \
  99.                 's/^-\{0,1\}[0-9]\{1,\}[:=][[:space:]]\{1,\}\([^[:space:](]\{3,\}\).*/%\1/p' )" \
  100.                 -- "$cur" ) )
  101.             return 0
  102.             ;;
  103.         --pipe)
  104.             COMPREPLY=( $( compgen -c -- "$cur" ) )
  105.             return 0
  106.             ;;
  107.         --rcfile)
  108.             _filedir
  109.             return 0
  110.             ;;
  111.         --specfile)
  112.             # complete on .spec files
  113.             _filedir spec
  114.             return 0
  115.             ;;
  116.         --whatprovides)
  117.             if [[ "$cur" == */* ]]; then
  118.                 _filedir
  119.             else
  120.                 # complete on capabilities
  121.             local IFS=$'\n'
  122.             COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig \
  123.                 --queryformat='%{providename}\n' )" -- "$cur" ) )
  124.             fi
  125.             return 0
  126.             ;;
  127.         --whatrequires)
  128.             if [[ "$cur" == */* ]]; then
  129.                 _filedir
  130.             else
  131.                 # complete on capabilities
  132.                 local IFS=$'\n'
  133.                 COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig \
  134.                         --queryformat='%{requirename}\n' )" \
  135.                         -- "$cur" ) )
  136.             fi
  137.             return 0
  138.             ;;
  139.         --target)
  140.             COMPREPLY=( $( compgen -W "$( command rpm --showrc | sed -ne \
  141.                 's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p' )" \
  142.                 -- "$cur" ) )
  143.             return 0
  144.             ;;
  145.         --define|-D)
  146.             # argument required but no completions available
  147.             return 0
  148.             ;;
  149.     esac
  150.  
  151.     # options common to all modes
  152.     opts="--define --eval --macros --nodigest --nosignature --rcfile \
  153.         --quiet --pipe --verbose"
  154.  
  155.     case ${COMP_WORDS[1]} in
  156.         -[iFU]*|--install|--freshen|--upgrade)
  157.             if [[ "$cur" == -* ]]; then
  158.                 COMPREPLY=( $( compgen -W "$opts --percent --force \
  159.                 --test --replacepkgs --replacefiles --root \
  160.                 --excludedocs --includedocs --noscripts --ignorearch \
  161.                 --dbpath --prefix --ignoreos --nodeps --allfiles \
  162.                 --ftpproxy --ftpport --justdb --httpproxy --httpport \
  163.                 --noorder --relocate --badreloc --notriggers \
  164.                 --excludepath --ignoresize --oldpackage \
  165.                 --queryformat --repackage --nosuggests" -- "$cur" ) )
  166.             else
  167.                 _filedir 'rpm'
  168.             fi
  169.             ;;
  170.         -e|--erase)
  171.             if [[ "$cur" == -* ]]; then
  172.                 COMPREPLY=( $( compgen -W "$opts --allmatches \
  173.                 --noscripts --notriggers --nodeps --test --repackage" \
  174.                 -- "$cur" ) )
  175.             else
  176.                 _rpm_installed_packages "$nodig" "$nosig"
  177.             fi
  178.             ;;
  179.         -q*|--query)
  180.             # options common to all query types
  181.             opts="$opts --changelog --configfiles --conflicts --docfiles
  182.                 --dump --enhances --filesbypkg --filecaps --fileclass
  183.                 --filecolor --fileprovide --filerequire --filesbypkg
  184.                 --info --list --obsoletes --pipe --provides
  185.                 --queryformat --rcfile --requires --scripts --suggests
  186.                 --triggeredby --triggers --whatprovides --whatrequires --xml"
  187.  
  188.             if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
  189.                 # -qf completion
  190.                 if [[ "$cur" == -* ]]; then
  191.                     COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \
  192.                         --last --root --state" -- "$cur" ) )
  193.                 else
  194.                     _filedir
  195.                 fi
  196.             elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
  197.                 # -qg completion
  198.                 _rpm_groups
  199.             elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
  200.                 # -qp; uninstalled package completion
  201.                 if [[ "$cur" == -* ]]; then
  202.                     COMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy \
  203.                         --httpport --httpproxy" -- "$cur" ) )
  204.                 else
  205.                     _filedir 'rpm'
  206.                 fi
  207.             else
  208.                 # -q; installed package completion
  209.                 if [[ "$cur" == -* ]]; then
  210.                     COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \
  211.                         --last --root --state" -- "$cur" ) )
  212.                 elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then
  213.                     _rpm_installed_packages "$nodig" "$nosig"
  214.                 fi
  215.             fi
  216.             ;;
  217.         -K*|--checksig)
  218.             if [[ "$cur" == -* ]]; then
  219.                 COMPREPLY=( $( compgen -W "$opts --nopgp --nogpg --nomd5" \
  220.                     -- "$cur" ) )
  221.             else
  222.                 _filedir 'rpm'
  223.             fi
  224.             ;;
  225.         -[Vy]*|--verify)
  226.             if [[ "$cur" == -* ]]; then
  227.                 COMPREPLY=( $( compgen -W "$opts --root --dbpath --nodeps \
  228.                     --nogroup --nolinkto --nomode --nomtime --nordev --nouser \
  229.                     --nofiles --noscripts --nomd5 --querytags --specfile \
  230.                     --whatrequires --whatprovides" -- "$cur" ) )
  231.             # check whether we're doing file completion
  232.             elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
  233.                 _filedir
  234.             elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
  235.                 _rpm_groups
  236.             elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
  237.                 _filedir 'rpm'
  238.             else
  239.                 _rpm_installed_packages "$nodig" "$nosig"
  240.             fi
  241.             ;;
  242.         -[bt]*)
  243.             if [[ "$cur" == -* ]]; then
  244.                 COMPREPLY=( $( compgen -W "$opts --short-circuit --timecheck \
  245.                     --clean --rmsource --rmspec --test --sign --buildroot \
  246.                     --target --nobuild --nodeps --nodirtokens" -- "$cur" ) )
  247.             elif [[ ${COMP_WORDS[1]} == -b* ]]; then
  248.                 _filedir 'spec'
  249.             else
  250.                 _filedir '@(t?(ar.)@([gx]z|bz?(2))|tar.@(lzma|Z))'
  251.             fi
  252.             ;;
  253.         --rebuild|--recompile)
  254.             if [[ "$cur" == -* ]]; then
  255.                 COMPREPLY=( $( compgen -W "$opts --nodeps --rmsource \
  256.                   --rmspec --sign --nodirtokens --target" -- "$cur" ) )
  257.             else
  258.                 _filedir '?(no)src.rpm'
  259.             fi
  260.             ;;
  261.         --tarbuild)
  262.             _filedir '@(t?(ar.)@([gx]z|bz?(2))|tar.@(lzma|Z))'
  263.             ;;
  264.         --resign|--addsign)
  265.             _filedir 'rpm'
  266.             ;;
  267.         --setperms|--setgids)
  268.             _rpm_installed_packages "$nodig" "$nosig"
  269.             ;;
  270.         --clean|--rmsource|--rmspec)
  271.             if [[ "$cur" == -* ]]; then
  272.                 COMPREPLY=( $( compgen -W '--clean --rmsource --rmspec' \
  273.                     -- "$cur" ) )
  274.             else
  275.                 _filedir 'spec'
  276.             fi
  277.             ;;
  278.         --import|--dbpath|--root)
  279.             if [[ "$cur" == -* ]]; then
  280.             COMPREPLY=( $( compgen -W '--import --dbpath --root' \
  281.                     -- "$cur" ) )
  282.             else
  283.                 _filedir
  284.             fi
  285.             ;;
  286.     esac
  287.  
  288.     return 0
  289. }
  290. complete -F _rpm -o filenames rpm rpmbuild
  291. }
  292.  
  293. # Local variables:
  294. # mode: shell-script
  295. # sh-basic-offset: 4
  296. # sh-indent-comment: t
  297. # indent-tabs-mode: nil
  298. # End:
  299. # ex: ts=4 sw=4 et filetype=sh
  300.