summaryrefslogtreecommitdiffstats
path: root/completions/dpkg
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:14:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:14:42 +0000
commit0bc58b66a4850cdb8458a86c3d9a2fc81de82aa3 (patch)
treeea0fe36eb5e6f40e0a1f765d44c4b0c0b2bfb089 /completions/dpkg
parentInitial commit. (diff)
downloadbash-completion-upstream.tar.xz
bash-completion-upstream.zip
Adding upstream version 1:2.11.upstream/1%2.11upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--completions/dpkg126
-rw-r--r--completions/dpkg-source98
2 files changed, 224 insertions, 0 deletions
diff --git a/completions/dpkg b/completions/dpkg
new file mode 100644
index 0000000..0b90b14
--- /dev/null
+++ b/completions/dpkg
@@ -0,0 +1,126 @@
+# This function is required by _dpkg and _dpkg-reconfigure -*- shell-script -*-
+
+_have grep-status && {
+ _comp_dpkg_installed_packages()
+ {
+ grep-status -P -e "^$1" -a -FStatus 'ok installed' -n -s Package
+ }
+} || {
+ _comp_dpkg_installed_packages()
+ {
+ command grep -A 1 "Package: $1" /var/lib/dpkg/status 2>/dev/null |
+ command grep -B 1 -Ee "ok installed|half-installed|unpacked| \
+ half-configured" \
+ -Ee "^Essential: yes" |
+ awk "/Package: $1/ { print \$2 }" 2>/dev/null
+ }
+}
+
+_have grep-status && {
+ _comp_dpkg_purgeable_packages()
+ {
+ grep-status -P -e "^$1" -a -FStatus 'ok installed' -o -FStatus 'ok config-files' -n -s Package
+ }
+} || {
+ _comp_dpkg_purgeable_packages()
+ {
+ command grep -A 1 "Package: $1" /var/lib/dpkg/status 2>/dev/null |
+ command grep -B 1 -Ee "ok installed|half-installed|unpacked| \
+ half-configured|config-files" \
+ -Ee "^Essential: yes" |
+ awk "/Package: $1/ { print \$2 }" 2>/dev/null
+ }
+}
+
+# Debian dpkg(1) completion
+#
+_dpkg()
+{
+ local cur prev words cword split
+ _init_completion -s || return
+
+ local i=$cword
+
+ # find the last option flag
+ if [[ $cur != -* ]]; then
+ while [[ $prev != -* && $i -ne 1 ]]; do
+ prev=${words[--i - 1]}
+ done
+ fi
+
+ case $prev in
+ --install | --unpack | --record-avail | --contents | --info | --fsys-tarfile | \
+ --field | --control | --extract | --vextract | --raw-extract | -!(-*)[ciAIfexX])
+ _filedir '?(u|d)deb'
+ return
+ ;;
+ --build | -!(-*)b)
+ _filedir -d
+ return
+ ;;
+ --status | --print-avail | --list | -!(-*)[spl])
+ COMPREPLY=($(_xfunc apt-cache _apt_cache_packages))
+ return
+ ;;
+ --show | -!(-*)W)
+ if [[ $1 == *dpkg-query ]]; then
+ COMPREPLY=($(_xfunc apt-cache _apt_cache_packages))
+ else
+ _filedir '?(u|d)deb'
+ fi
+ return
+ ;;
+ --search | -!(-*)S)
+ _filedir
+ return
+ ;;
+ --remove | --verify | -!(-*)[rV])
+ COMPREPLY=($(_comp_dpkg_installed_packages "$cur"))
+ return
+ ;;
+ --listfiles | --purge | -!(-*)[LP])
+ COMPREPLY=($(_comp_dpkg_purgeable_packages "$cur"))
+ return
+ ;;
+ esac
+
+ $split && return
+
+ COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
+ [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
+} &&
+ complete -F _dpkg dpkg dpkg-deb dpkg-query
+
+# Debian GNU dpkg-reconfigure(8) completion
+#
+_dpkg_reconfigure()
+{
+ local cur prev words cword
+ _init_completion || return
+
+ local opt
+
+ case $prev in
+ --frontend | -!(-*)f)
+ opt=($(printf '%s\n' /usr/share/perl5/Debconf/FrontEnd/*))
+ opt=(${opt[@]##*/})
+ opt=(${opt[@]%.pm})
+ COMPREPLY=($(compgen -W '${opt[@]}' -- "$cur"))
+ return
+ ;;
+ --priority | -!(-*)p)
+ COMPREPLY=($(compgen -W 'low medium high critical' -- "$cur"))
+ return
+ ;;
+ esac
+
+ if [[ $cur == -* ]]; then
+ COMPREPLY=($(compgen -W '--frontend --priority --all --unseen-only
+ --help --showold --force --terse' -- "$cur"))
+ else
+ COMPREPLY=($(_comp_dpkg_installed_packages "$cur"))
+ fi
+} &&
+ complete -F _dpkg_reconfigure -o default dpkg-reconfigure
+
+# ex: filetype=sh
diff --git a/completions/dpkg-source b/completions/dpkg-source
new file mode 100644
index 0000000..05fa3a1
--- /dev/null
+++ b/completions/dpkg-source
@@ -0,0 +1,98 @@
+# Debian dpkg-source completion -*- shell-script -*-
+
+_dpkg_source()
+{
+ local cur prev words cword
+ _init_completion || return
+
+ local options word action packopts unpackopts fields
+
+ packopts="-c -l -F -V -T -D -U -W -E -sa -i -I -sk -sr -ss -sA -sK -sP \
+ -sU -sR"
+ unpackopts="-sp -sn -su"
+ options="-x -b --print-format --before-build --after-build --commit $packopts $unpackopts"
+ fields="Format Source Version Binary Maintainer Uploader Architecture \
+ Standards-Version Build-Depends Files"
+
+ action=options
+ for word in "${words[@]:1}"; do
+ if [[ $word == -x ]]; then
+ action=unpack
+ elif [[ $word == -b ]]; then
+ action=pack
+ elif [[ $word == -h ]]; then
+ action=help
+ fi
+ done
+
+ case $action in
+ unpack)
+ case $prev in
+ -x)
+ _filedir -d
+ _filedir 'dsc'
+ ;;
+ *)
+ COMPREPLY=($(compgen -W "$unpackopts" -- "$cur"))
+ _filedir -d
+ _filedir
+ ;;
+ esac
+ return
+ ;;
+ pack)
+ case $prev in
+ -b)
+ _filedir -d
+ ;;
+ -c | -l | -T | -i | -I)
+ # -c: get controlfile
+ # -l: get per-version info from this file
+ # -T: read variables here, not debian/substvars
+ # -i: <regexp> filter out files to ignore diffs of.
+ # -I: filter out files when building tarballs.
+ # return directory names and file names
+ _filedir -d
+ _filedir
+ ;;
+ -F)
+ # -F: force change log format
+ COMPREPLY=($(command ls /usr/lib/dpkg/parsechangelog))
+ ;;
+ -V)
+ # -V: set a substitution variable
+ # we don't know anything about possible variables or values
+ # so we don't try to suggest any completion.
+ COMPREPLY=()
+ ;;
+ -D)
+ # -D: override or add a .dsc field and value
+ # if $cur doesn't contain a = yet, suggest variable names
+ if [[ $cur == *=* ]]; then
+ # $cur contains a "="
+ COMPREPLY=()
+ else
+ COMPREPLY=($(compgen -W "$fields" -- "$cur"))
+ fi
+ ;;
+ -U)
+ # -U: remove a field
+ # Suggest possible fieldnames
+ COMPREPLY=($(compgen -W "$fields" -- "$cur"))
+ ;;
+ *)
+ COMPREPLY=($(compgen -W "$packopts $unpackopts" \
+ -- "$cur"))
+ ;;
+ esac
+ return
+ ;;
+ *)
+ COMPREPLY=($(compgen -W "$options" -- "$cur"))
+ return
+ ;;
+ esac
+} &&
+ complete -F _dpkg_source dpkg-source
+
+# ex: filetype=sh