-
Notifications
You must be signed in to change notification settings - Fork 412
Deprecate dpkg completion #1639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
81fa434
e40090a
a3a3a82
0ed5033
767ebba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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")" | ||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just lists the filenames, so there is no need to use the external executable One may first call
Suggested change
Or, actually, it may be simpler to use
Suggested change
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| _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 | ||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||
|
Comment on lines
+57
to
+67
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I see the command-line parser of the redhat implementation, We should explicitly see the nearest option name to generate the command line arguments. |
||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||
|
scop marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # dpkg-reconfigure(1) 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
localvar_inherit, local variables need to be explicitly initialized.