You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

228 lines
6.9 KiB

  1. # Debian apt(8) completion -*- shell-script -*-
  2. _apt()
  3. {
  4. local sourcesdir="/etc/apt/sources.list.d"
  5. local cur prev words cword
  6. _init_completion || return
  7. local GENERIC_APT_GET_OPTIONS='
  8. -d --download-only
  9. -y --assume-yes
  10. --assume-no
  11. -u --show-upgraded
  12. -m --ignore-missing
  13. -t --target-release
  14. --download
  15. --fix-missing
  16. --ignore-hold
  17. --upgrade
  18. --only-upgrade
  19. --allow-change-held-packages
  20. --allow-remove-essential
  21. --allow-downgrades
  22. --print-uris
  23. --trivial-only
  24. --remove
  25. --arch-only
  26. --allow-unauthenticated
  27. --allow-insecure-repositories
  28. --install-recommends
  29. --install-suggests
  30. --no-install-recommends
  31. --no-install-suggests
  32. --fix-policy
  33. '
  34. # see if the user selected a command already
  35. local COMMANDS=(
  36. "list"
  37. "search"
  38. "show" "showsrc"
  39. "install" "remove" "purge" "autoremove"
  40. "update"
  41. "upgrade" "full-upgrade" "dist-upgrade"
  42. "edit-sources"
  43. "help"
  44. "source" "build-dep"
  45. "clean" "autoclean"
  46. "download" "changelog"
  47. "moo"
  48. "depends" "rdepends"
  49. "policy")
  50. local command i
  51. for (( i=0; i < ${#words[@]}-1; i++ )); do
  52. if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
  53. command=${words[i]}
  54. break
  55. fi
  56. done
  57. # Complete a -t<SPACE><TAB>
  58. case $prev in
  59. -t|--target-release)
  60. COMPREPLY=( $( compgen -W "$(apt-cache policy | egrep -o 'a=[^,]*|n=[^,]*' | cut -f2- -d= | sort -u)" -- "$cur" ) )
  61. return 0
  62. ;;
  63. esac
  64. # supported options per command
  65. if [[ "$cur" == -* ]]; then
  66. case $command in
  67. install|remove|purge|upgrade|dist-upgrade|full-upgrade|autoremove)
  68. COMPREPLY=( $( compgen -W '--show-progress
  69. --fix-broken --purge --verbose-versions --auto-remove
  70. -s --simulate --dry-run
  71. --download
  72. --fix-missing
  73. --fix-policy
  74. --ignore-hold
  75. --force-yes
  76. --trivial-only
  77. --reinstall --solver
  78. -t --target-release'"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
  79. return 0
  80. ;;
  81. update)
  82. COMPREPLY=( $( compgen -W '--list-cleanup
  83. --print-uris
  84. --allow-insecure-repositories
  85. ' -- "$cur" ) )
  86. return 0
  87. ;;
  88. list)
  89. COMPREPLY=( $( compgen -W '--installed --upgradable
  90. --manual-installed
  91. -v --verbose
  92. -a --all-versions
  93. -t --target-release
  94. ' -- "$cur" ) )
  95. return 0
  96. ;;
  97. show)
  98. COMPREPLY=( $( compgen -W '-a --all-versions
  99. ' -- "$cur" ) )
  100. return 0
  101. ;;
  102. depends|rdepends)
  103. COMPREPLY=( $( compgen -W '-i
  104. --important
  105. --installed
  106. --pre-depends
  107. --depends
  108. --recommends
  109. --suggests
  110. --replaces
  111. --breaks
  112. --conflicts
  113. --enhances
  114. --recurse
  115. --implicit' -- "$cur" ) )
  116. return 0
  117. ;;
  118. search)
  119. COMPREPLY=( $( compgen -W '
  120. -n --names-only
  121. -f --full' -- "$cur" ) )
  122. return 0
  123. ;;
  124. showsrc)
  125. COMPREPLY=( $( compgen -W '
  126. --only-source' -- "$cur" ) )
  127. return 0
  128. ;;
  129. source)
  130. COMPREPLY=( $( compgen -W '
  131. -s --simulate --dry-run
  132. -b --compile --build
  133. -P --build-profiles
  134. --diff-only --debian-only
  135. --tar-only
  136. --dsc-only
  137. -t --target-release
  138. '"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
  139. return 0
  140. ;;
  141. build-dep)
  142. COMPREPLY=( $( compgen -W '
  143. -a --host-architecture
  144. -s --simulate --dry-run
  145. -P --build-profiles
  146. -t --target-release
  147. --purge --solver
  148. '"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
  149. return 0
  150. ;;
  151. moo)
  152. COMPREPLY=( $( compgen -W '
  153. --color
  154. ' -- "$cur" ) )
  155. return 0
  156. ;;
  157. clean|autoclean)
  158. COMPREPLY=( $( compgen -W '
  159. -s --simulate --dry-run
  160. ' -- "$cur" ) )
  161. return 0
  162. ;;
  163. esac
  164. fi
  165. # specific command arguments
  166. if [[ -n $command ]]; then
  167. case $command in
  168. remove|purge|autoremove)
  169. if [[ -f /etc/debian_version ]]; then
  170. # Debian system
  171. COMPREPLY=( $( \
  172. _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
  173. else
  174. # assume RPM based
  175. _xfunc rpm _rpm_installed_packages
  176. fi
  177. return 0
  178. ;;
  179. show|list|download|changelog|depends|rdepends)
  180. COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
  181. 2> /dev/null ) )
  182. return 0
  183. ;;
  184. install)
  185. COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
  186. 2> /dev/null ) )
  187. if [[ "$cur" == ./* || "$cur" == /* ]]; then
  188. _filedir "deb"
  189. fi
  190. return 0
  191. ;;
  192. source|build-dep|showsrc|policy)
  193. COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
  194. 2> /dev/null ) $( apt-cache dumpavail | \
  195. command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
  196. return 0
  197. ;;
  198. edit-sources)
  199. COMPREPLY=( $( compgen -W '$( command ls $sourcesdir )' \
  200. -- "$cur" ) )
  201. return 0
  202. ;;
  203. moo)
  204. COMPREPLY=( $( compgen -W 'moo' \
  205. -- "$cur" ) )
  206. return 0
  207. ;;
  208. esac
  209. fi
  210. # no command yet, show what commands we have
  211. if [ "$command" = "" ]; then
  212. COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )
  213. fi
  214. return 0
  215. } &&
  216. complete -F _apt apt
  217. # ex: ts=4 sw=4 et filetype=sh