/bash_completion_lib/complete -o filenames/rpm

http://github.com/brinkman83/bashrc · #! · 258 lines · 246 code · 12 blank · 0 comment · 0 complexity · 9874ef6500d1067b655a67e4df191c17 MD5 · raw file

  1. # rpm(8) completion
  2. comp_include _filedir _get_cword _rpm_installed_packages
  3. _rpm_groups()
  4. {
  5. local IFS=$'\t'
  6. # remove trailing backslash, or grep will complain
  7. cur=${cur%"\\"}
  8. COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat '%{group}\n' | \
  9. grep "^$cur" ) )
  10. # backslash escape spaces and translate newlines to tabs
  11. COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
  12. }
  13. _rpm()
  14. {
  15. local cur prev ver nodig nosig
  16. COMPREPLY=()
  17. cur=`_get_cword`
  18. prev=${COMP_WORDS[COMP_CWORD-1]}
  19. nodig=""
  20. nosig=""
  21. ver=$(rpm --version); ver=${ver##* }
  22. if [[ "$ver" > "4.0.4" ]]; then
  23. nodig="--nodigest"
  24. fi
  25. if [[ "$ver" > "4.0.99" ]]; then
  26. nosig="--nosignature"
  27. fi
  28. if [ $COMP_CWORD -eq 1 ]; then
  29. # first parameter on line
  30. case "$cur" in
  31. -b*)
  32. COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs'\
  33. -- $cur ) )
  34. ;;
  35. -t*)
  36. COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts'\
  37. -- $cur ) )
  38. ;;
  39. --*)
  40. COMPREPLY=( $( compgen -W '--help --version --initdb \
  41. --checksig --recompile --rebuild --resign --addsign \
  42. --rebuilddb --showrc --setperms --setugids --tarbuild \
  43. --eval --install --upgrade --query --freshen --erase \
  44. --verify --querytags --rmsource --rmspec --clean \
  45. --import' -- $cur ) )
  46. ;;
  47. *)
  48. COMPREPLY=( $( compgen -W '-b -e -F -i -q -t -U -V' \
  49. -- $cur ) )
  50. ;;
  51. esac
  52. return 0
  53. fi
  54. case "$prev" in
  55. --@(@(db|exclude)path|prefix|relocate|root))
  56. _filedir -d
  57. return 0
  58. ;;
  59. --eval)
  60. # get a list of macros
  61. COMPREPLY=( $( sed -ne 's|^\(%'${cur#\%}'[^ '$'\t'']*\).*$|\1|p' \
  62. /usr/lib/rpm/macros ) )
  63. return 0
  64. ;;
  65. --pipe)
  66. COMPREPLY=( $( compgen -c -- $cur ) )
  67. return 0
  68. ;;
  69. --rcfile)
  70. _filedir
  71. return 0
  72. ;;
  73. --specfile)
  74. # complete on .spec files
  75. _filedir spec
  76. return 0
  77. ;;
  78. --whatprovides)
  79. if [[ "$cur" == */* ]]; then
  80. _filedir
  81. else
  82. # complete on capabilities
  83. COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \
  84. '%{providename}\n' | grep "^$cur" ) )
  85. fi
  86. return 0
  87. ;;
  88. --whatrequires)
  89. # complete on capabilities
  90. COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \
  91. '%{requirename}\n' | grep "^$cur" ) )
  92. return 0
  93. ;;
  94. esac
  95. case "${COMP_WORDS[1]}" in
  96. -@([iFU]*|-install|-freshen|-upgrade))
  97. if [[ "$cur" == -* ]]; then
  98. COMPREPLY=( $( compgen -W '--percent --force --test \
  99. --replacepkgs --replacefiles --root --excludedocs \
  100. --includedocs --noscripts --rcfile --ignorearch \
  101. --dbpath --prefix --ignoreos --nodeps --allfiles \
  102. --ftpproxy --ftpport --justdb --httpproxy --httpport \
  103. --noorder --relocate --badreloc --notriggers \
  104. --excludepath --ignoresize --oldpackage --define \
  105. --eval --pipe --queryformat --repackage --nosuggests \
  106. --nodigest --nosignature' -- $cur ) )
  107. else
  108. _filedir 'rpm'
  109. fi
  110. ;;
  111. -@(e|-erase))
  112. if [[ "$cur" == -* ]]; then
  113. COMPREPLY=( $( compgen -W '--allmatches --noscripts \
  114. --notriggers --nodeps --test --repackage' -- $cur ) )
  115. else
  116. _rpm_installed_packages
  117. fi
  118. ;;
  119. -@(q*|-query))
  120. # check whether we're doing file completion
  121. if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
  122. if [[ "$cur" == -* ]]; then
  123. COMPREPLY=( $( compgen -W '--scripts --root \
  124. --rcfile --requires --ftpport --ftpproxy \
  125. --httpproxy --httpport --provides --triggers \
  126. --dump --changelog --dbpath \
  127. --last --filesbypkg \
  128. --info --list --state \
  129. --docfiles --configfiles --queryformat \
  130. --conflicts --obsoletes \
  131. --nodigest --nosignature \
  132. --triggerscripts' -- $cur ) )
  133. else
  134. _filedir
  135. fi
  136. elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
  137. _rpm_groups
  138. elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
  139. # uninstalled package completion
  140. if [[ "$cur" == -* ]]; then
  141. COMPREPLY=( $( compgen -W '--scripts --root \
  142. --rcfile --whatprovides --whatrequires \
  143. --requires --triggeredby --ftpport --ftpproxy \
  144. --httpproxy --httpport --provides --triggers \
  145. --dump --changelog --dbpath --filesbypkg \
  146. --define --eval --pipe --showrc --info --list \
  147. --state --docfiles --configfiles --queryformat\
  148. --conflicts --obsoletes --nodigest \
  149. --nosignature' -- $cur ) )
  150. else
  151. _filedir 'rpm'
  152. fi
  153. else
  154. # installed package completion
  155. if [[ "$cur" == -* ]]; then
  156. COMPREPLY=( $( compgen -W '--scripts --root \
  157. --rcfile --whatprovides --whatrequires \
  158. --requires --triggeredby --ftpport --ftpproxy \
  159. --httpproxy --httpport --provides --triggers \
  160. --dump --changelog --dbpath --specfile \
  161. --querybynumber --last --filesbypkg --define \
  162. --eval --pipe --showrc --info --list --state \
  163. --docfiles --configfiles --queryformat \
  164. --conflicts --obsoletes --pkgid --hdrid \
  165. --fileid --tid --nodigest --nosignature \
  166. --triggerscripts' -- $cur ) )
  167. elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then
  168. _rpm_installed_packages
  169. fi
  170. fi
  171. ;;
  172. -@(K*|-checksig))
  173. if [[ "$cur" == -* ]]; then
  174. COMPREPLY=( $( compgen -W '--nopgp --nogpg --nomd5 \
  175. --nodigest --nosignature' -- $cur ) )
  176. else
  177. _filedir 'rpm'
  178. fi
  179. ;;
  180. -@([Vy]*|-verify))
  181. if [[ "$cur" == -* ]]; then
  182. COMPREPLY=( $( compgen -W '--root --rcfile --dbpath \
  183. --nodeps --nogroup --nolinkto --nomode --nomtime \
  184. --nordev --nouser --nofiles --noscripts --nomd5 \
  185. --querytags --specfile --whatrequires --whatprovides \
  186. --nodigest --nosignature' -- $cur ) )
  187. # check whether we're doing file completion
  188. elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
  189. _filedir
  190. elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
  191. _rpm_groups
  192. elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
  193. _filedir 'rpm'
  194. else
  195. _rpm_installed_packages
  196. fi
  197. ;;
  198. -[bt]*)
  199. if [[ "$cur" == -* ]]; then
  200. COMPREPLY=( $( compgen -W '--short-circuit --timecheck \
  201. --clean --rmsource --rmspec --test --sign --buildroot \
  202. --target -- buildarch --buildos --nobuild --nodeps \
  203. --nodirtokens' -- $cur ) )
  204. elif [[ ${COMP_WORDS[1]} == -b* ]]; then
  205. _filedir 'spec'
  206. else
  207. _filedir '@(tgz|tar.@(gz|bz2))'
  208. fi
  209. ;;
  210. --re@(build|compile))
  211. if [[ "$cur" == -* ]]; then
  212. COMPREPLY=( $( compgen -W '--nodeps --rmsource \
  213. --rmspec --sign --nodirtokens --target' -- $cur ) )
  214. else
  215. _filedir '?(no)src.rpm'
  216. fi
  217. ;;
  218. --tarbuild)
  219. _filedir '@(tgz|tar.@(gz|bz2))'
  220. ;;
  221. --@(re|add)sign)
  222. _filedir 'rpm'
  223. ;;
  224. --set@(perms|gids))
  225. _rpm_installed_packages
  226. ;;
  227. --@(clean|rms@(ource|pec)))
  228. if [[ "$cur" == -* ]]; then
  229. COMPREPLY=( $( compgen -W '--clean --rmsource \
  230. --rmspec' -- $cur ) )
  231. else
  232. _filedir 'spec'
  233. fi
  234. ;;
  235. --@(import|dbpath|root))
  236. if [[ "$cur" == -* ]]; then
  237. COMPREPLY=( $( compgen -W '--import --dbpath --root' \
  238. -- $cur ) )
  239. else
  240. _filedir
  241. fi
  242. ;;
  243. esac
  244. return 0
  245. }
  246. _rpm