summaryrefslogtreecommitdiff
path: root/completions/apt-cache
diff options
context:
space:
mode:
Diffstat (limited to 'completions/apt-cache')
-rw-r--r--completions/apt-cache46
1 files changed, 28 insertions, 18 deletions
diff --git a/completions/apt-cache b/completions/apt-cache
index 085a964d..bedae4e9 100644
--- a/completions/apt-cache
+++ b/completions/apt-cache
@@ -1,5 +1,20 @@
# Debian apt-cache(8) completion -*- shell-script -*-
+# List APT binary packages
+_apt_cache_packages() {
+ apt-cache --no-generate pkgnames "$cur" 2> /dev/null
+}
+
+# List APT source packages
+_apt_cache_sources() {
+ apt-cache dumpavail | command grep "^Source: $1" | cut -f2 -d" " | sort -u
+}
+
+# List APT source packages
+_apt_cache_src_packages() {
+ compgen -W '$( _apt_cache_sources "$cur" )' -- "$cur"
+}
+
_apt_cache()
{
local cur prev words cword
@@ -19,34 +34,31 @@ _apt_cache()
case $special in
add)
_filedir
- return 0
;;
showsrc)
- COMPREPLY=( $( apt-cache dumpavail | \
- command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
- return 0
+ COMPREPLY=( $( _apt_cache_sources "$cur" ) )
;;
*)
- COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" 2> /dev/null ) )
- return 0
+ COMPREPLY=( $( _apt_cache_packages ) )
;;
esac
+ return
fi
case $prev in
- -c|-p|-s|--config-file|--pkg-cache|--src-cache)
- _filedir
- return 0
- ;;
- search)
- if [[ "$cur" != -* ]]; then
- return 0
- fi
- ;;
+ -c|-p|-s|--config-file|--pkg-cache|--src-cache)
+ _filedir
+ return
+ ;;
+ search)
+ if [[ "$cur" != -* ]]; then
+ return
+ fi
+ ;;
esac
if [[ "$cur" == -* ]]; then
@@ -64,9 +76,7 @@ _apt_cache()
fi
-
- return 0
} &&
complete -F _apt_cache apt-cache
-# ex: ts=4 sw=4 et filetype=sh
+# ex: filetype=sh