summaryrefslogtreecommitdiff
path: root/completions/bash
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-05-13 10:06:31 +0200
committerJulian Andres Klode <jak@debian.org>2016-05-20 19:49:08 +0200
commit30d84f1bb3efb69acb936ace3506c04a00b521a9 (patch)
tree1b9aeaccfbe3762c3ce48256dd1577ad1c6438c9 /completions/bash
parentcde5b485c9cdf0bfd5b6ea8e4973abe378270e60 (diff)
Provide complete apt bash completion
This fixes Debian/apt#13 and the launchpad bug listed below, but is far more advanced. I went through private-cmndline.cc and looked at the supported options. LP: #1573547 Thanks: Elias Fröhner and Svyatoslav Gryaznov for the initial work (cherry picked from commit 5aba18968d87500232244760101ab2954c106581)
Diffstat (limited to 'completions/bash')
-rw-r--r--completions/bash/apt128
1 files changed, 122 insertions, 6 deletions
diff --git a/completions/bash/apt b/completions/bash/apt
index d7104ec5a..451004982 100644
--- a/completions/bash/apt
+++ b/completions/bash/apt
@@ -6,16 +6,48 @@ _apt()
local cur prev words cword
_init_completion || return
+ local GENERIC_APT_GET_OPTIONS='
+ -d --download-only
+ -y --assume-yes
+ --assume-no
+ -u --show-upgraded
+ -m --ignore-missing
+ -t --target-release
+ --download
+ --fix-missing
+ --ignore-hold
+ --upgrade
+ --only-upgrade
+ --allow-change-held-packages
+ --allow-remove-essential
+ --allow-downgrades
+ --print-uris
+ --trivial-only
+ --remove
+ --arch-only
+ --allow-unauthenticated
+ --allow-insecure-repositories
+ --install-recommends
+ --install-suggests
+ --fix-policy
+ '
+
# see if the user selected a command already
local COMMANDS=(
"list"
"search"
- "show"
+ "show" "showsrc"
"install" "remove" "purge" "autoremove"
"update"
"upgrade" "full-upgrade" "dist-upgrade"
"edit-sources"
- "help")
+ "help"
+ "source" "build-dep"
+ "clean" "autoclean"
+ "download" "changelog"
+ "moo"
+ "depends" "rdepends"
+ "policy")
local command i
for (( i=0; i < ${#words[@]}-1; i++ )); do
@@ -25,24 +57,35 @@ _apt()
fi
done
+ # Complete a -t<SPACE><TAB>
+ case $prev in
+ -t|--target-release)
+ COMPREPLY=( $( compgen -W "$(apt-cache policy | egrep -o 'a=[^,]*|n=[^,]*' | cut -f2- -d= | sort -u)" -- "$cur" ) )
+ return 0
+ ;;
+ esac
+
# supported options per command
if [[ "$cur" == -* ]]; then
case $command in
install|remove|purge|upgrade|dist-upgrade|full-upgrade|autoremove)
COMPREPLY=( $( compgen -W '--show-progress
--fix-broken --purge --verbose-versions --auto-remove
- --simulate --dry-run
+ -s --simulate --dry-run
--download
--fix-missing
--fix-policy
--ignore-hold
--force-yes
--trivial-only
- --reinstall --solver' -- "$cur" ) )
+ --reinstall --solver
+ -t --target-release'"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
return 0
;;
update)
- COMPREPLY=( $( compgen -W '--list-cleanup
+ COMPREPLY=( $( compgen -W '--list-cleanup
+ --print-uris
+ --allow-insecure-repositories
' -- "$cur" ) )
return 0
;;
@@ -51,6 +94,7 @@ _apt()
--manual-installed
-v --verbose
-a --all-versions
+ -t --target-release
' -- "$cur" ) )
return 0
;;
@@ -59,6 +103,67 @@ _apt()
' -- "$cur" ) )
return 0
;;
+ depends|rdepends)
+ COMPREPLY=( $( compgen -W '-i
+ --important
+ --installed
+ --pre-depends
+ --depends
+ --recommends
+ --suggests
+ --replaces
+ --breaks
+ --conflicts
+ --enhances
+ --recurse
+ --implicit' -- "$cur" ) )
+ return 0
+ ;;
+ search)
+ COMPREPLY=( $( compgen -W '
+ -n --names-only
+ -f --full' -- "$cur" ) )
+ return 0
+ ;;
+ showsrc)
+ COMPREPLY=( $( compgen -W '
+ --only-source' -- "$cur" ) )
+ return 0
+ ;;
+ source)
+ COMPREPLY=( $( compgen -W '
+ -s --simulate --dry-run
+ -b --compile --build
+ -P --build-profiles
+ --diff-only --debian-only
+ --tar-only
+ --dsc-only
+ -t --target-release
+ '"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
+ return 0
+ ;;
+ build-dep)
+ COMPREPLY=( $( compgen -W '
+ -a --host-architecture
+ -s --simulate --dry-run
+ -P --build-profiles
+ -t --target-release
+ --purge --solver
+ '"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
+ return 0
+ ;;
+ moo)
+ COMPREPLY=( $( compgen -W '
+ --color
+ ' -- "$cur" ) )
+ return 0
+ ;;
+ clean|autocleean)
+ COMPREPLY=( $( compgen -W '
+ -s --simulate --dry-run
+ ' -- "$cur" ) )
+ return 0
+ ;;
esac
fi
@@ -76,7 +181,7 @@ _apt()
fi
return 0
;;
- show|list)
+ show|list|download|changelog|depends|rdepends)
COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
2> /dev/null ) )
return 0
@@ -87,11 +192,22 @@ _apt()
_filedir "*.deb"
return 0
;;
+ source|build-dep|showsrc|policy)
+ COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
+ 2> /dev/null ) $( apt-cache dumpavail | \
+ command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
+ return 0
+ ;;
edit-sources)
COMPREPLY=( $( compgen -W '$( command ls $sourcesdir )' \
-- "$cur" ) )
return 0
;;
+ moo)
+ COMPREPLY=( $( compgen -W 'moo' \
+ -- "$cur" ) )
+ return 0
+ ;;
esac
fi