diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:03:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:03:18 +0000 |
commit | f2621414ee5f2f601424c22f00e207903e3b6104 (patch) | |
tree | 56a856dafd1ca684bb23263cacaa723ee4f404fc /completions/dpkg | |
parent | Adding debian version 1:2.11-8. (diff) | |
download | bash-completion-f2621414ee5f2f601424c22f00e207903e3b6104.tar.xz bash-completion-f2621414ee5f2f601424c22f00e207903e3b6104.zip |
Merging upstream version 1:2.12.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'completions/dpkg')
-rw-r--r-- | completions/dpkg | 188 |
1 files changed, 122 insertions, 66 deletions
diff --git a/completions/dpkg b/completions/dpkg index 0b90b14..7ce5c19 100644 --- a/completions/dpkg +++ b/completions/dpkg @@ -1,43 +1,67 @@ -# This function is required by _dpkg and _dpkg-reconfigure -*- shell-script -*- +# dpkg(1) and related commands completion -*- 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 - } +# @since 2.12 +_comp_xfunc_dpkg_compgen_installed_packages() +{ + _comp_compgen_split -- "$( + grep-status -P -e "^${cur-}" -a \ + -FStatus 'ok installed' \ + -n -s Package 2>/dev/null || + _comp_awk -F '\n' -v RS="" " + index(\$1, \"Package: ${cur-}\") == 1 && + \$2 ~ /ok installed|half-installed|unpacked|half-configured|^Essential: yes/ { + print(substr(\$1, 10)); + }" /var/lib/dpkg/status 2>/dev/null + )" +} + +# @since 2.12 +_comp_xfunc_dpkg_compgen_purgeable_packages() +{ + _comp_compgen_split -- "$( + grep-status -P -e "^${cur-}" -a \ + -FStatus 'ok installed' -o -FStatus 'ok config-files' \ + -n -s Package 2>/dev/null || + _comp_awk -F '\n' -v RS="" " + index(\$1, \"Package: ${cur-}\") == 1 && + \$2 ~ /ok installed|half-installed|unpacked|half-configured|config-files|^Essential: yes/ { + print(substr(\$1, 10)); + }" /var/lib/dpkg/status 2>/dev/null + )" +} + +# @since 2.12 +_comp_xfunc_dpkg_compgen_held_packages() +{ + _comp_compgen_split -- "$( + dpkg --get-selections ${cur:+"$cur}"} | + _comp_awk '{for(i=2;i<=NF;i++){ if($i=="hold"){ print $1;break }}}' + )" } -_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 - } +# @deprecated 2.12 use _comp_xfunc_dpkg_compgen_installed_packages instead +_comp_dpkg_installed_packages() +{ + local COMPREPLY=() cur="${1-}" + # shellcheck disable=SC2119 + _comp_xfunc_dpkg_compgen_installed_packages + printf "%s\n" "${COMPREPLY[@]}" +} +# @deprecated 2.12 use _comp_xfunc_dpkg_compgen_purgeable_packages instead +_comp_dpkg_purgeable_packages() +{ + local COMPREPLY=() cur="${1-}" + # shellcheck disable=SC2119 + _comp_xfunc_dpkg_compgen_purgeable_packages + printf "%s\n" "${COMPREPLY[@]}" } # Debian dpkg(1) completion # -_dpkg() +_comp_cmd_dpkg() { - local cur prev words cword split - _init_completion -s || return + local cur prev words cword was_split comp_args + _comp_initialize -s -- "$@" || return local i=$cword @@ -48,79 +72,111 @@ _dpkg() done fi + local noargopts='!(-*|*[ciAIfexXbsplWSrVLPD]*)' + # shellcheck disable=SC2254 case $prev in --install | --unpack | --record-avail | --contents | --info | --fsys-tarfile | \ - --field | --control | --extract | --vextract | --raw-extract | -!(-*)[ciAIfexX]) - _filedir '?(u|d)deb' + --field | --control | --extract | --vextract | --raw-extract | -${noargopts}[ciAIfexX]) + _comp_compgen_filedir '?(u|d)deb' return ;; - --build | -!(-*)b) - _filedir -d + --build | --admindir | --instdir | --root | -${noargopts}b) + _comp_compgen_filedir -d return ;; - --status | --print-avail | --list | -!(-*)[spl]) - COMPREPLY=($(_xfunc apt-cache _apt_cache_packages)) + --status | --print-avail | --list | -${noargopts}[spl]) + _comp_compgen -x apt-cache packages return ;; - --show | -!(-*)W) + --show | -${noargopts}W) if [[ $1 == *dpkg-query ]]; then - COMPREPLY=($(_xfunc apt-cache _apt_cache_packages)) + _comp_compgen -x apt-cache packages else - _filedir '?(u|d)deb' + _comp_compgen_filedir '?(u|d)deb' fi return ;; - --search | -!(-*)S) - _filedir + --search | -${noargopts}S) + _comp_compgen_filedir + return + ;; + --remove | --verify | -${noargopts}[rV]) + _comp_xfunc_dpkg_compgen_installed_packages return ;; - --remove | --verify | -!(-*)[rV]) - COMPREPLY=($(_comp_dpkg_installed_packages "$cur")) + --listfiles | --purge | -${noargopts}[LP]) + _comp_xfunc_dpkg_compgen_purgeable_packages return ;; - --listfiles | --purge | -!(-*)[LP]) - COMPREPLY=($(_comp_dpkg_purgeable_packages "$cur")) + --debug | -${noargopts}D) + _comp_compgen -- -W 'help' + return + ;; + --ignore-depends) + local packages + _comp_compgen -v packages -c "${cur##*,}" -x apt-cache packages + _comp_delimited , -W '"${packages[@]}"' + return + ;; + --log) + _comp_compgen_filedir log + return + ;; + --path-exclude | --path-include) + return + ;; + --status-logger) + _comp_compgen_commands + return + ;; + --verify-format) + _comp_compgen -- -W 'rpm' return ;; esac - $split && return + [[ $was_split ]] && return - COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) + _comp_compgen_help + for i in ${!COMPREPLY[*]}; do + # remove ones ending with a dash (known parse issue, hard to fix) + [[ ${COMPREPLY[i]} != *- ]] || unset -v 'COMPREPLY[i]' + done [[ ${COMPREPLY-} == *= ]] && compopt -o nospace } && - complete -F _dpkg dpkg dpkg-deb dpkg-query + complete -F _comp_cmd_dpkg dpkg dpkg-deb dpkg-query -# Debian GNU dpkg-reconfigure(8) completion -# -_dpkg_reconfigure() +_comp_cmd_dpkg_reconfigure() { - local cur prev words cword - _init_completion || return + local cur prev words cword comp_args + _comp_initialize -- "$@" || return local opt + local noargopts='!(-*|*[fp]*)' + # shellcheck disable=SC2254 case $prev in - --frontend | -!(-*)f) - opt=($(printf '%s\n' /usr/share/perl5/Debconf/FrontEnd/*)) - opt=(${opt[@]##*/}) - opt=(${opt[@]%.pm}) - COMPREPLY=($(compgen -W '${opt[@]}' -- "$cur")) + --frontend | -${noargopts}f) + if _comp_expand_glob opt '/usr/share/perl5/Debconf/FrontEnd/*'; then + opt=("${opt[@]##*/}") + opt=("${opt[@]%.pm}") + _comp_compgen -- -W '"${opt[@]}"' + fi return ;; - --priority | -!(-*)p) - COMPREPLY=($(compgen -W 'low medium high critical' -- "$cur")) + --priority | -${noargopts}p) + _comp_compgen -- -W 'low medium high critical' return ;; esac if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '--frontend --priority --all --unseen-only - --help --showold --force --terse' -- "$cur")) + _comp_compgen -- -W '--frontend --priority --all --unseen-only --help + --showold --force --terse' else - COMPREPLY=($(_comp_dpkg_installed_packages "$cur")) + _comp_xfunc_dpkg_compgen_installed_packages fi } && - complete -F _dpkg_reconfigure -o default dpkg-reconfigure + complete -F _comp_cmd_dpkg_reconfigure -o default dpkg-reconfigure # ex: filetype=sh |