diff --git a/completions-core/.gitignore b/completions-core/.gitignore index 9b8ea2ed6fe..04687247dc0 100644 --- a/completions-core/.gitignore +++ b/completions-core/.gitignore @@ -4,7 +4,6 @@ /7zzs.bash /aclocal-1.1[012345678].bash /alpine.bash -/alternatives.bash /animate.bash /apropos.bash /aptitude-curses.bash @@ -45,8 +44,6 @@ /dcop.bash /dfutool.bash /display.bash -/dpkg-deb.bash -/dpkg-query.bash /dpkg-reconfigure.bash /dropdb.bash /dropuser.bash diff --git a/completions-core/Makefile.am b/completions-core/Makefile.am index f4dba26601a..d36a3356d3a 100644 --- a/completions-core/Makefile.am +++ b/completions-core/Makefile.am @@ -6,6 +6,7 @@ cross_platform = 2to3.bash \ acpi.bash \ add_members.bash \ alias.bash \ + alternatives.bash \ ant.bash \ apache2ctl.bash \ appdata-validate.bash \ @@ -74,6 +75,7 @@ cross_platform = 2to3.bash \ cvs.bash \ cvsps.bash \ dd.bash \ + debconf.bash \ declare.bash \ deja-dup.bash \ desktop-file-validate.bash \ @@ -83,9 +85,6 @@ cross_platform = 2to3.bash \ dnssec-keygen.bash \ dnsspoof.bash \ dot.bash \ - dpkg.bash \ - dpkg-source.bash \ - dselect.bash \ dsniff.bash \ dumpdb.bash \ dumpe2fs.bash \ @@ -399,7 +398,6 @@ cross_platform = 2to3.bash \ unpack200.bash \ unrar.bash \ unshunt.bash \ - update-alternatives.bash \ update-rc.d.bash \ upgradepkg.bash \ urlsnarf.bash \ @@ -490,7 +488,6 @@ CLEANFILES = \ aclocal-1.17.bash \ aclocal-1.18.bash \ alpine.bash \ - alternatives.bash \ animate.bash \ apropos.bash \ aptitude-curses.bash \ @@ -539,8 +536,6 @@ CLEANFILES = \ dcop.bash \ dfutool.bash \ display.bash \ - dpkg-deb.bash \ - dpkg-query.bash \ dpkg-reconfigure.bash \ dropdb.bash \ dropuser.bash \ @@ -861,12 +856,12 @@ symlinks: $(DATA) mogrify montage stream $(ss) cowsay \ cowthink + $(ss) debconf \ + dpkg-reconfigure $(ss) declare \ typeset $(ss) dict \ rdict - $(ss) dpkg \ - dpkg-deb dpkg-query dpkg-reconfigure $(ss) ether-wake \ etherwake $(ss) filesnarf \ @@ -1021,8 +1016,6 @@ endif bsdtar gtar star $(ss) tracepath \ tracepath6 - $(ss) update-alternatives \ - alternatives $(ss) vipw \ vigr $(ss) vncviewer \ diff --git a/completions-core/alternatives.bash b/completions-core/alternatives.bash new file mode 100644 index 00000000000..7214599faa4 --- /dev/null +++ b/completions-core/alternatives.bash @@ -0,0 +1,95 @@ +# bash completion for alternatives + +_comp_cmd_alternatives__installed() +{ + local i admindir + # find the admin dir + for i in alternatives rpm/alternatives; do + [[ -d /var/lib/$i ]] && admindir=/var/lib/$i && break + done + for ((i = 1; i < cword; i++)); do + if [[ ${words[i]} == --admindir ]]; then + admindir=${words[i + 1]} + break + fi + done + [[ -d $admindir ]] && _comp_compgen_split -- "$(command ls "$admindir")" +} + +_comp_cmd_alternatives() +{ + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + + case $prev in + --altdir | --admindir) + _comp_compgen_filedir -d + return + ;; + --help | --usage | --version) + return + ;; + esac + + local mode="" args i + + # find which mode to use and how many real args used so far + for ((i = 1; i < cword; i++)); do + if [[ ${words[i]} == --@(install|remove|auto|display|config|remove-all|set) ]]; then + mode=${words[i]} + args=$((cword - i)) + break + fi + done + + case ${mode-} in + --install) + case $args in + 1 | 3) + _comp_compgen_filedir + ;; + 2) + _comp_cmd_alternatives__installed + ;; + 4) + # priority - no completions + ;; + *) + case $((args % 4)) in + 0 | 2) + _comp_compgen_filedir + ;; + 1) + _comp_compgen -- -W '--slave' + ;; + 3) + _comp_cmd_alternatives__installed + ;; + esac + ;; + esac + ;; + --remove | --set) + case $args in + 1) + _comp_cmd_alternatives__installed + ;; + 2) + _comp_compgen_filedir + ;; + esac + ;; + --auto | --remove-all | --display | --config) + _comp_cmd_alternatives__installed + ;; + *) + _comp_compgen_help - <<<"$(LANG=C "$1" --help 2>&1 | command sed ' + /usage:/,/^[[:space:]]*$/{ + s/^\([[:space:]]*usage:\)\{0,1\}[[:space:]]*[^[:space:]]*alternatives / / + s/^[[:space:]]*\[\(-.*\)\]/ \1/ + } + /common options:/,$s/ --/\n --/g')" + ;; + esac +} && + complete -F _comp_cmd_alternatives alternatives diff --git a/completions-core/debconf.bash b/completions-core/debconf.bash new file mode 100644 index 00000000000..c0b11817f6b --- /dev/null +++ b/completions-core/debconf.bash @@ -0,0 +1,34 @@ +# debconf(1) and related commands completion + +_comp_cmd_dpkg_reconfigure() +{ + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + + local opt + + local noargopts='!(-*|*[fp]*)' + # shellcheck disable=SC2254 + case $prev in + --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 | -${noargopts}p) + _comp_compgen -- -W 'low medium high critical' + return + ;; + esac + + if [[ $cur == -* ]]; then + _comp_compgen -- -W '--frontend --priority --all --unseen-only --help + --showold --force --terse' + else + _comp_compgen -x dpkg installed_packages + fi +} && + complete -F _comp_cmd_dpkg_reconfigure -o default dpkg-reconfigure diff --git a/completions-fallback/.gitignore b/completions-fallback/.gitignore index fde12fbf5ef..7b27cb71596 100644 --- a/completions-fallback/.gitignore +++ b/completions-fallback/.gitignore @@ -58,6 +58,8 @@ /dive.bash /dlv.bash /docker.bash +/dpkg-deb.bash +/dpkg-query.bash /dprint.bash /driftctl.bash /dyff.bash diff --git a/completions-fallback/Makefile.am b/completions-fallback/Makefile.am index 1e65b6817fc..67e15db80c9 100644 --- a/completions-fallback/Makefile.am +++ b/completions-fallback/Makefile.am @@ -8,6 +8,9 @@ cross_platform = adb.bash \ coder.bash \ delta.bash \ dmesg.bash \ + dpkg.bash \ + dpkg-source.bash \ + dselect.bash \ eject.bash \ flamegraph.bash \ gaiacli.bash \ @@ -63,6 +66,7 @@ cross_platform = adb.bash \ task.bash \ tokio-console.bash \ udevadm.bash \ + update-alternatives.bash \ umount.bash \ umount.linux.bash \ uvx.bash \ @@ -83,6 +87,7 @@ CLEANFILES = \ airflow.bash \ allero.bash \ alp.bash \ + alternatives.bash \ ansible.bash \ ansible-config.bash \ ansible-console.bash \ @@ -140,6 +145,8 @@ CLEANFILES = \ dive.bash \ dlv.bash \ docker.bash \ + dpkg-deb.bash \ + dpkg-query.bash \ dprint.bash \ driftctl.bash \ dyff.bash \ @@ -316,6 +323,9 @@ symlinks: $(DATA) mago release-plz $(ss) cal \ ncal + $(ss) dpkg \ + dpkg-deb \ + dpkg-query $(ss) flamegraph \ just \ watchexec @@ -537,6 +547,8 @@ symlinks: $(DATA) uv $(ss) sops \ kata-runtime todoist + $(ss) update-alternatives \ + alternatives $(ss) vault \ bao \ consul \ diff --git a/completions-core/dpkg-source.bash b/completions-fallback/dpkg-source.bash similarity index 96% rename from completions-core/dpkg-source.bash rename to completions-fallback/dpkg-source.bash index 71d5529a560..90fbdab5e60 100644 --- a/completions-core/dpkg-source.bash +++ b/completions-fallback/dpkg-source.bash @@ -1,5 +1,8 @@ # Debian dpkg-source completion +# Use of this file is deprecated. Upstream completion is available in +# dpkg >= 1.23.8, use that instead. + _comp_cmd_dpkg_source() { local cur prev words cword comp_args diff --git a/completions-core/dpkg.bash b/completions-fallback/dpkg.bash similarity index 82% rename from completions-core/dpkg.bash rename to completions-fallback/dpkg.bash index 00417ee8046..db02324ae9a 100644 --- a/completions-core/dpkg.bash +++ b/completions-fallback/dpkg.bash @@ -1,5 +1,8 @@ # dpkg(1) and related commands completion +# Use of this file is deprecated. Upstream completion is available in +# dpkg >= 1.23.8, use that instead. + # @since 2.12 _comp_xfunc_dpkg_compgen_installed_packages() { @@ -145,36 +148,3 @@ _comp_cmd_dpkg() [[ ${COMPREPLY-} == *= ]] && compopt -o nospace } && complete -F _comp_cmd_dpkg dpkg dpkg-deb dpkg-query - -_comp_cmd_dpkg_reconfigure() -{ - local cur prev words cword comp_args - _comp_initialize -- "$@" || return - - local opt - - local noargopts='!(-*|*[fp]*)' - # shellcheck disable=SC2254 - case $prev in - --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 | -${noargopts}p) - _comp_compgen -- -W 'low medium high critical' - return - ;; - esac - - if [[ $cur == -* ]]; then - _comp_compgen -- -W '--frontend --priority --all --unseen-only --help - --showold --force --terse' - else - _comp_xfunc_dpkg_compgen_installed_packages - fi -} && - complete -F _comp_cmd_dpkg_reconfigure -o default dpkg-reconfigure diff --git a/completions-core/dselect.bash b/completions-fallback/dselect.bash similarity index 83% rename from completions-core/dselect.bash rename to completions-fallback/dselect.bash index 0d00379e935..a2f7dbd7c23 100644 --- a/completions-core/dselect.bash +++ b/completions-fallback/dselect.bash @@ -1,5 +1,8 @@ # Debian Linux dselect(8) completion +# Use of this file is deprecated. Upstream completion is available in +# dpkg >= 1.23.8, use that instead. + _comp_cmd_dselect() { local cur prev words cword comp_args diff --git a/completions-core/update-alternatives.bash b/completions-fallback/update-alternatives.bash similarity index 96% rename from completions-core/update-alternatives.bash rename to completions-fallback/update-alternatives.bash index 352413261ae..df7ddad16e2 100644 --- a/completions-core/update-alternatives.bash +++ b/completions-fallback/update-alternatives.bash @@ -1,5 +1,8 @@ # bash completion for update-alternatives +# Use of this file is deprecated. Upstream completion is available in +# dpkg >= 1.23.8, use that instead. + _comp_cmd_update_alternatives__installed() { local i admindir @@ -92,4 +95,4 @@ _comp_cmd_update_alternatives() ;; esac } && - complete -F _comp_cmd_update_alternatives update-alternatives alternatives + complete -F _comp_cmd_update_alternatives update-alternatives