From 3c20766a6248aec000eb55731dd6b159ecf45dc2 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 02:21:28 +0900 Subject: [PATCH 01/11] fix(_comp_compgen): do not inherit -a for explicitly specified var --- bash_completion | 9 +++++++-- test/t/unit/test_unit_compgen.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bash_completion b/bash_completion index 94861ca5562..939fe0942a8 100644 --- a/bash_completion +++ b/bash_completion @@ -520,8 +520,8 @@ _comp_compgen__error_fallback() # @since 2.12 _comp_compgen() { - local _append=${_comp_compgen__append-} - local _var=${_comp_compgen__var-COMPREPLY} + local _append= + local _var= local _cur=${_comp_compgen__cur-${cur-}} local _dir="" local _ifs=$' \t\n' _has_ifs="" @@ -592,6 +592,11 @@ _comp_compgen() printf 'usage: %s [-alR|-F SEP|-v ARR|-c CUR] -- ARGS...' "$FUNCNAME" >&2 return 2 fi + if [[ ! $_var ]]; then + # Inherit _append and _var only when -v var is unspecified. + _var=${_comp_compgen__var-COMPREPLY} + [[ $_append ]] || _append=${_comp_compgen__append-} + fi if [[ $1 != -* ]]; then # usage: _comp_compgen [options] NAME args diff --git a/test/t/unit/test_unit_compgen.py b/test/t/unit/test_unit_compgen.py index f28e9a2b135..cfdec8ee017 100644 --- a/test/t/unit/test_unit_compgen.py +++ b/test/t/unit/test_unit_compgen.py @@ -43,6 +43,13 @@ def functions(self, bash): "_comp_compgen_gen8() { local -a arr=(x y z); _comp_compgen -U arr -- -W '\"${arr[@]}\"'; }", ) + # test_9_inherit_a + assert_bash_exec( + bash, + '_comp_compgen_gen9sub() { local -a gen=(00); _comp_compgen -v gen -- -W 11; _comp_compgen_set "${gen[@]}"; }; ' + "_comp_compgen_gen9() { _comp_compgen_gen9sub; _comp_compgen -a gen9sub; }", + ) + def test_1_basic(self, bash, functions): output = assert_bash_exec( bash, "_comp__test_words 12 34 56 ''", want_output=True @@ -158,3 +165,9 @@ def test_8_option_U(self, bash, functions): bash, "_comp__test_compgen gen8", want_output=True ) assert output.strip() == "" + + def test_9_inherit_a(self, bash, functions): + output = assert_bash_exec( + bash, "_comp__test_compgen gen9", want_output=True + ) + assert output.strip() == "<11><11>" From 5e1d2fa461a4a5baa194a98776294c1ab1c7e3a6 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 00:36:32 +0900 Subject: [PATCH 02/11] refactor: rename `{ => _comp_compgen}_services` --- bash_completion | 19 ++++++++++--------- .../000_bash_completion_compat.bash | 1 + completions/chkconfig | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bash_completion b/bash_completion index 939fe0942a8..2b78d93fd7d 100644 --- a/bash_completion +++ b/bash_completion @@ -1917,27 +1917,28 @@ _comp_compgen_xinetd_services() # This function completes on services # -# TODO:API: rename per conventions -_services() +# @since 2.12 +_comp_compgen_services() { local sysvdirs _comp_sysvdirs - _comp_expand_glob COMPREPLY '${sysvdirs[0]}/!($_comp_backup_glob|functions|README)' + local services + _comp_expand_glob services '${sysvdirs[0]}/!($_comp_backup_glob|functions|README)' - local generated=$({ + local _generated=$({ systemctl list-units --full --all || systemctl list-unit-files } 2>/dev/null | awk '$1 ~ /\.service$/ { sub("\\.service$", "", $1); print $1 }') - _comp_split -la COMPREPLY "$generated" + _comp_split -la services "$_generated" if [[ -x /sbin/upstart-udev-bridge ]]; then - _comp_split -la COMPREPLY "$(initctl list 2>/dev/null | cut -d' ' -f1)" + _comp_split -la services "$(initctl list 2>/dev/null | cut -d' ' -f1)" fi - ((${#COMPREPLY[@]})) && - _comp_compgen -- -W '"${COMPREPLY[@]#${sysvdirs[0]}/}"' + ((${#services[@]})) || return 1 + _comp_compgen -U services -U sysvdirs -- -W '"${services[@]#${sysvdirs[0]}/}"' } # This completes on a list of all available service scripts for the @@ -1957,7 +1958,7 @@ _service() ((cword > 2)) && return if [[ $cword -eq 1 && $prev == ?(*/)service ]]; then - _services + _comp_compgen_services [[ -e /etc/mandrake-release ]] && _comp_compgen_xinetd_services else local sysvdirs diff --git a/bash_completion.d/000_bash_completion_compat.bash b/bash_completion.d/000_bash_completion_compat.bash index 67bae75e130..88bf6515bfa 100644 --- a/bash_completion.d/000_bash_completion_compat.bash +++ b/bash_completion.d/000_bash_completion_compat.bash @@ -21,6 +21,7 @@ _comp_deprecate_func 2.12 _kernel_versions _comp_compgen_kernel_versions _comp_deprecate_func 2.12 _uids _comp_compgen_uids _comp_deprecate_func 2.12 _gids _comp_compgen_gids _comp_deprecate_func 2.12 _xinetd_services _comp_compgen_xinetd_services +_comp_deprecate_func 2.12 _services _comp_compgen_services _comp_deprecate_func 2.12 _pids _comp_compgen_pids _comp_deprecate_func 2.12 _pgids _comp_compgen_pgids _comp_deprecate_func 2.12 _pnames _comp_compgen_pnames diff --git a/completions/chkconfig b/completions/chkconfig index 605938e6d5d..32c33920f65 100644 --- a/completions/chkconfig +++ b/completions/chkconfig @@ -7,7 +7,7 @@ _comp_cmd_chkconfig() case $prev in --level=[1-6] | [1-6] | --list | --add | --del | --override) - _services + _comp_compgen_services _comp_compgen -a xinetd_services return ;; @@ -25,7 +25,7 @@ _comp_cmd_chkconfig() if ((cword == 2 || cword == 4)); then _comp_compgen -- -W 'on off reset resetpriorities' else - _services + _comp_compgen_services _comp_compgen -a xinetd_services fi fi From 7b7aac8da7fe681183bd2774c7bbc9d4bb210c77 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 01:27:51 +0900 Subject: [PATCH 03/11] refactor: rename `_{ => comp}_expand_tilde{_by_ref => }` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ville Skyttä --- bash_completion | 42 ++++++++++--------- .../000_bash_completion_compat.bash | 20 +++++++++ completions/mutt | 10 +++-- completions/sbopkg | 6 +-- completions/slapt-get | 5 ++- completions/slapt-src | 5 ++- test/t/unit/Makefile.am | 2 +- ...de_by_ref.py => test_unit_expand_tilde.py} | 35 ++++++++++------ 8 files changed, 81 insertions(+), 44 deletions(-) rename test/t/unit/{test_unit_expand_tilde_by_ref.py => test_unit_expand_tilde.py} (56%) diff --git a/bash_completion b/bash_completion index 2b78d93fd7d..2084eaa305d 100644 --- a/bash_completion +++ b/bash_completion @@ -1734,7 +1734,7 @@ _comp_compgen_tilde() return 1 } -# Expand variable starting with tilde (~) +# Expand string starting with tilde (~) # We want to expand ~foo/... to /home/foo/... to avoid problems when # word-to-complete starting with a tilde is fed to commands and ending up # quoted instead of expanded. @@ -1743,11 +1743,11 @@ _comp_compgen_tilde() # a dollar sign variable ($) or asterisk (*) is not expanded. # Example usage: # -# $ v="~"; __expand_tilde_by_ref v; echo "$v" +# $ _comp_expand_tilde "~"; echo "$ret" # # Example output: # -# v output +# $1 ret # -------- ---------------- # ~ /home/user # ~foo/bar /home/foo/bar @@ -1755,14 +1755,17 @@ _comp_compgen_tilde() # ~foo/a b /home/foo/a b # ~foo/* /home/foo/* # -# @param $1 Name of variable (not the value of the variable) to expand -# TODO:API: rename per conventions -__expand_tilde_by_ref() +# @param $1 Value to expand +# @var[out] ret Expanded result +# @since 2.12 +_comp_expand_tilde() { - if [[ ${!1-} == \~* ]]; then - eval "$1"="$(printf ~%q "${!1#\~}")" + ret=$1 + if [[ $1 == \~* ]]; then + printf -v ret '~%q' "${1#\~}" + eval "ret=$ret" fi -} # __expand_tilde_by_ref() +} # This function expands tildes in pathnames # @@ -1775,7 +1778,9 @@ _expand() case ${cur-} in ~*/*) - __expand_tilde_by_ref cur + local ret + _comp_expand_tilde "$cur" + cur=$ret ;; ~*) _comp_compgen -v COMPREPLY tilde && @@ -2376,7 +2381,7 @@ _comp__included_ssh_config_files() { (($# < 1)) && echo "bash_completion: $FUNCNAME: missing mandatory argument CONFIG" >&2 - local configfile i files f + local configfile i files f ret configfile=$1 # From man ssh_config: @@ -2408,9 +2413,9 @@ _comp__included_ssh_config_files() if [[ $i != [~/]* ]]; then i="${relative_include_base}/${i}" fi - __expand_tilde_by_ref i + _comp_expand_tilde "$i" + _comp_expand_glob files '$ret' # In case the expanded variable contains multiple paths - _comp_expand_glob files '$i' if ((${#files[@]})); then for f in "${files[@]}"; do if [[ -r $f && ! -d $f ]]; then @@ -2509,20 +2514,19 @@ _known_hosts_real() # spaces in their name work (watch out for ~ expansion # breakage! Alioth#311595) if _comp_split -l tmpkh "$(awk 'sub("^[ \t]*([Gg][Ll][Oo][Bb][Aa][Ll]|[Uu][Ss][Ee][Rr])[Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee][ \t=]+", "") { print $0 }' "${config[@]}" | sort -u)"; then - local tmpkh2 j + local tmpkh2 j ret for i in "${tmpkh[@]}"; do # First deal with quoted entries... while [[ $i =~ ^([^\"]*)\"([^\"]*)\"(.*)$ ]]; do i=${BASH_REMATCH[1]}${BASH_REMATCH[3]} - j=${BASH_REMATCH[2]} - __expand_tilde_by_ref j # Eval/expand possible `~' or `~user' - [[ -r $j ]] && kh+=("$j") + _comp_expand_tilde "${BASH_REMATCH[2]}" # Eval/expand possible `~' or `~user' + [[ -r $ret ]] && kh+=("$ret") done # ...and then the rest. _comp_split tmpkh2 "$i" || continue for j in "${tmpkh2[@]}"; do - __expand_tilde_by_ref j # Eval/expand possible `~' or `~user' - [[ -r $j ]] && kh+=("$j") + _comp_expand_tilde "$j" # Eval/expand possible `~' or `~user' + [[ -r $ret ]] && kh+=("$ret") done done fi diff --git a/bash_completion.d/000_bash_completion_compat.bash b/bash_completion.d/000_bash_completion_compat.bash index 88bf6515bfa..a155d3dcf27 100644 --- a/bash_completion.d/000_bash_completion_compat.bash +++ b/bash_completion.d/000_bash_completion_compat.bash @@ -360,6 +360,26 @@ _ncpus() printf %s "$ret" } +# Expand variable starting with tilde (~). +# We want to expand ~foo/... to /home/foo/... to avoid problems when +# word-to-complete starting with a tilde is fed to commands and ending up +# quoted instead of expanded. +# Only the first portion of the variable from the tilde up to the first slash +# (~../) is expanded. The remainder of the variable, containing for example +# a dollar sign variable ($) or asterisk (*) is not expanded. +# +# @deprecated 2.12 Use `_comp_expand_tilde`. The new function receives the +# value instead of a variable name as $1 and always returns the result to the +# variable `ret`. +__expand_tilde_by_ref() +{ + [[ ${1+set} ]] || return 0 + [[ $1 == ret ]] || local ret + _comp_expand_tilde "${!1-}" + # shellcheck disable=SC2059 + [[ $1 == ret ]] || printf -v "$1" "$ret" +} # __expand_tilde_by_ref() + # @deprecated 2.12 Use `_comp_compgen -a cd_devices` _cd_devices() { diff --git a/completions/mutt b/completions/mutt index 2b6a5b8fb08..b2033a8c0e3 100644 --- a/completions/mutt +++ b/completions/mutt @@ -72,10 +72,10 @@ _comp_cmd_mutt__get_conffiles__visit() local -a newconffiles=($(command sed -n 's|^source[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*$|\1|p' "$1")) ((${#newconffiles[@]})) || return 0 - local file + local file ret for file in "${newconffiles[@]}"; do - __expand_tilde_by_ref file - _comp_cmd_mutt__get_conffiles__visit "$file" + _comp_expand_tilde "$file" + _comp_cmd_mutt__get_conffiles__visit "$ret" done } @@ -119,7 +119,9 @@ _comp_cmd_mutt__query() if [[ ! $cur || ! $querycmd ]]; then queryresults=() else - __expand_tilde_by_ref querycmd + local ret + _comp_expand_tilde "$querycmd" + querycmd=$ret # $querycmd is expected to be a command with arguments queryresults=($($querycmd | command sed -n '2,$s|^\([^[:space:]]\{1,\}\).*|\1|p')) diff --git a/completions/sbopkg b/completions/sbopkg index 7483d83fce4..865382524a4 100644 --- a/completions/sbopkg +++ b/completions/sbopkg @@ -34,12 +34,12 @@ _comp_cmd_sbopkg() ;; esac - local i config + local i ret config config="/etc/sbopkg/sbopkg.conf" for ((i = ${#words[@]} - 2; i > 0; i--)); do if [[ ${words[i]} == -f ]]; then - config="${words[i + 1]}" - __expand_tilde_by_ref config + _comp_expand_tilde "${words[i + 1]}" + config=$ret break fi done diff --git a/completions/slapt-get b/completions/slapt-get index 0085ed428c9..5a27a760f8e 100644 --- a/completions/slapt-get +++ b/completions/slapt-get @@ -47,8 +47,9 @@ _comp_cmd_slapt_get() # search for config for ((i = ${#words[@]} - 1; i > 0; i--)); do if [[ ${words[i]} == -@(c|-config) ]]; then - config="${words[i + 1]}" - __expand_tilde_by_ref config + local ret + _comp_expand_tilde "${words[i + 1]}" + config=$ret break fi done diff --git a/completions/slapt-src b/completions/slapt-src index 5a1bb6e94e5..04d671a7085 100644 --- a/completions/slapt-src +++ b/completions/slapt-src @@ -42,8 +42,9 @@ _comp_cmd_slapt_src() # search for config for ((i = ${#words[@]} - 1; i > 0; i--)); do if [[ ${words[i]} == -@(c|-config) ]]; then - config="${words[i + 1]}" - __expand_tilde_by_ref config + local ret + _comp_expand_tilde "${words[i + 1]}" + config=$ret break fi if [[ ${words[i]} == --config=?* ]]; then diff --git a/test/t/unit/Makefile.am b/test/t/unit/Makefile.am index fa14d15647d..47f6e56a416 100644 --- a/test/t/unit/Makefile.am +++ b/test/t/unit/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST = \ test_unit_dequote.py \ test_unit_expand.py \ test_unit_expand_glob.py \ - test_unit_expand_tilde_by_ref.py \ + test_unit_expand_tilde.py \ test_unit_filedir.py \ test_unit_find_unique_completion_pair.py \ test_unit_get_first_arg.py \ diff --git a/test/t/unit/test_unit_expand_tilde_by_ref.py b/test/t/unit/test_unit_expand_tilde.py similarity index 56% rename from test/t/unit/test_unit_expand_tilde_by_ref.py rename to test/t/unit/test_unit_expand_tilde.py index 1ab58362dc9..e9506b59ca9 100644 --- a/test/t/unit/test_unit_expand_tilde_by_ref.py +++ b/test/t/unit/test_unit_expand_tilde.py @@ -3,16 +3,27 @@ from conftest import assert_bash_exec -@pytest.mark.bashcomp(cmd=None, ignore_env=r"^[+-](home|var)=") -class TestUnitExpandTildeByRef: +@pytest.mark.bashcomp(cmd=None) +class TestUnitExpandTilde: def test_1(self, bash): + """The old interface `__expand_tilde_by_ref` should not fail when it is + called without arguments""" assert_bash_exec(bash, "__expand_tilde_by_ref >/dev/null") def test_2(self, bash): """Test environment non-pollution, detected at teardown.""" assert_bash_exec( bash, - '_x() { local aa="~"; __expand_tilde_by_ref aa; }; _x; unset -f _x', + '_x() { local ret; _comp_expand_tilde "~"; }; _x; unset -f _x', + ) + + @pytest.fixture(scope="class") + def functions(self, bash): + # $HOME tinkering: protect against $HOME != ~user; our "home" is the + # latter but plain_tilde follows $HOME + assert_bash_exec( + bash, + '_comp__test_unit() { local ret HOME=$1; _comp_expand_tilde "$2"; printf "%s\\n" "$ret"; }', ) @pytest.mark.parametrize("plain_tilde", (True, False)) @@ -28,23 +39,21 @@ def test_2(self, bash): ("/a;echo hello", True), ), ) - def test_expand(self, bash, user_home, plain_tilde, suffix_expanded): + def test_expand( + self, bash, user_home, plain_tilde, suffix_expanded, functions + ): user, home = user_home suffix, expanded = suffix_expanded - # $HOME tinkering: protect against $HOME != ~user; our "home" is the - # latter but plain_tilde follows $HOME - assert_bash_exec(bash, 'home="$HOME"; HOME="%s"' % home) + home2 = home if plain_tilde: user = "" if not suffix or not expanded: - home = "~" + home2 = "~" elif not expanded: - home = "~%s" % user + home2 = "~%s" % user output = assert_bash_exec( bash, - r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"' - % (user, suffix), + r'_comp__test_unit "%s" "~%s%s"' % (home, user, suffix), want_output=True, ) - assert_bash_exec(bash, 'HOME="$home"') - assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$")) + assert output.strip() == "%s%s" % (home2, suffix.replace(r"\$", "$")) From 7015db3119a85484190c1aa04938a34b658e9b34 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 01:38:31 +0900 Subject: [PATCH 04/11] refactor: rename `{ => _comp}_expand` --- bash_completion | 4 ++-- bash_completion.d/000_bash_completion_compat.bash | 1 + completions/povray | 2 +- completions/rsync | 2 +- completions/ssh | 2 +- completions/sshfs | 2 +- test/t/unit/test_unit_expand.py | 10 +++++----- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bash_completion b/bash_completion index 2084eaa305d..06b7198ce6e 100644 --- a/bash_completion +++ b/bash_completion @@ -1769,8 +1769,8 @@ _comp_expand_tilde() # This function expands tildes in pathnames # -# TODO:API: rename per conventions -_expand() +# @since 2.12 +_comp_expand() { # Expand ~username type directory specifications. We want to expand # ~foo/... to /home/foo/... to avoid problems when $cur starting with diff --git a/bash_completion.d/000_bash_completion_compat.bash b/bash_completion.d/000_bash_completion_compat.bash index a155d3dcf27..090f50b679e 100644 --- a/bash_completion.d/000_bash_completion_compat.bash +++ b/bash_completion.d/000_bash_completion_compat.bash @@ -22,6 +22,7 @@ _comp_deprecate_func 2.12 _uids _comp_compgen_uids _comp_deprecate_func 2.12 _gids _comp_compgen_gids _comp_deprecate_func 2.12 _xinetd_services _comp_compgen_xinetd_services _comp_deprecate_func 2.12 _services _comp_compgen_services +_comp_deprecate_func 2.12 _expand _comp_expand _comp_deprecate_func 2.12 _pids _comp_compgen_pids _comp_deprecate_func 2.12 _pgids _comp_compgen_pgids _comp_deprecate_func 2.12 _pnames _comp_compgen_pnames diff --git a/completions/povray b/completions/povray index 7032a32ed69..3a840ddd1c3 100644 --- a/completions/povray +++ b/completions/povray @@ -9,7 +9,7 @@ _comp_cmd_povray() local povcur=$cur pfx oext defoext defoext=png # default output extension, if cannot be determined FIXME - _expand || return + _comp_expand || return case $povcur in [-+]I*) diff --git a/completions/rsync b/completions/rsync index 2fa2dcc1bac..24f0d77ddaf 100644 --- a/completions/rsync +++ b/completions/rsync @@ -56,7 +56,7 @@ _comp_cmd_rsync() [[ $was_split ]] && return - _expand || return + _comp_expand || return case $cur in -*) diff --git a/completions/ssh b/completions/ssh index f219c8592a2..d324cde2148 100644 --- a/completions/ssh +++ b/completions/ssh @@ -597,7 +597,7 @@ _comp_cmd_scp() ;; esac - _expand || return + _comp_expand || return case $cur in !(*:*)/* | [.~]*) ;; # looks like a path diff --git a/completions/sshfs b/completions/sshfs index 34d25e773d9..21d0be442b5 100644 --- a/completions/sshfs +++ b/completions/sshfs @@ -5,7 +5,7 @@ _comp_cmd_sshfs() local cur prev words cword comp_args _comp_initialize -n : -- "$@" || return - _expand || return + _comp_expand || return if [[ $cur == *:* ]]; then _comp_compgen -x scp remote_files -d diff --git a/test/t/unit/test_unit_expand.py b/test/t/unit/test_unit_expand.py index e0a562d9306..0be6c52bfdb 100644 --- a/test/t/unit/test_unit_expand.py +++ b/test/t/unit/test_unit_expand.py @@ -6,17 +6,17 @@ @pytest.mark.bashcomp(cmd=None, ignore_env=r"^[+-](cur|COMPREPLY)=") class TestUnitExpand: def test_1(self, bash): - assert_bash_exec(bash, "_expand >/dev/null") + assert_bash_exec(bash, "_comp_expand >/dev/null") def test_2(self, bash): """Test environment non-pollution, detected at teardown.""" - assert_bash_exec(bash, "foo() { _expand; }; foo; unset -f foo") + assert_bash_exec(bash, "foo() { _comp_expand; }; foo; unset -f foo") def test_user_home_compreply(self, bash, user_home): user, home = user_home output = assert_bash_exec( bash, - r'cur="~%s"; _expand; printf "%%s\n" "$COMPREPLY"' % user, + r'cur="~%s"; _comp_expand; printf "%%s\n" "$COMPREPLY"' % user, want_output=True, ) assert output.strip() == home @@ -27,7 +27,7 @@ def test_user_home_compreply_failglob(self, bash, user_home): bash_env.shopt("failglob", True) output = assert_bash_exec( bash, - r'cur="~%s"; _expand; printf "%%s\n" "$COMPREPLY"' % user, + r'cur="~%s"; _comp_expand; printf "%%s\n" "$COMPREPLY"' % user, want_output=True, ) assert output.strip() == home @@ -36,7 +36,7 @@ def test_user_home_cur(self, bash, user_home): user, home = user_home output = assert_bash_exec( bash, - r'cur="~%s/a"; _expand; printf "%%s\n" "$cur"' % user, + r'cur="~%s/a"; _comp_expand; printf "%%s\n" "$cur"' % user, want_output=True, ) assert output.strip() == "%s/a" % home From 812f0fe9966af5f1b939a845254448d3840233c2 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 11 Aug 2023 18:02:11 +0900 Subject: [PATCH 05/11] refactor: rename `{ => _comp_compgen}_shells` --- bash_completion | 14 ++++++++------ bash_completion.d/000_bash_completion_compat.bash | 6 ++++++ completions/_chsh | 2 +- completions/_su | 2 +- completions/luseradd | 2 +- completions/mussh | 2 +- completions/screen | 2 +- completions/useradd | 2 +- completions/usermod | 2 +- 9 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bash_completion b/bash_completion index 06b7198ce6e..759a0d3c232 100644 --- a/bash_completion +++ b/bash_completion @@ -2092,15 +2092,17 @@ _comp_compgen_selinux_users() } # This function completes on valid shells -# # @param $1 chroot to search from -# TODO:API: rename per conventions -_shells() +# +# @since 2.12 +_comp_compgen_shells() { - local shell rest - while read -r shell rest; do - [[ $shell == /* && $shell == "$cur"* ]] && COMPREPLY+=("$shell") + local -a shells=() + local _shell _rest + while read -r _shell _rest; do + [[ $_shell == /* ]] && shells+=("$_shell") done 2>/dev/null <"${1-}"/etc/shells + _comp_compgen -U shells -- -W '"${shells[@]}"' } # This function completes on valid filesystem types diff --git a/bash_completion.d/000_bash_completion_compat.bash b/bash_completion.d/000_bash_completion_compat.bash index 090f50b679e..597c7e22f5b 100644 --- a/bash_completion.d/000_bash_completion_compat.bash +++ b/bash_completion.d/000_bash_completion_compat.bash @@ -423,6 +423,12 @@ _allowed_groups() _comp_compgen -c "${1:-$cur}" allowed_groups } +# @deprecated 2.12 Use `_comp_compgen -a shells` +_shells() +{ + _comp_compgen -a shells +} + # @deprecated 2.12 Use `_comp_compgen -a fstypes` _fstypes() { diff --git a/completions/_chsh b/completions/_chsh index b0e6b86e02e..4e243ba024a 100644 --- a/completions/_chsh +++ b/completions/_chsh @@ -26,7 +26,7 @@ _comp_cmd_chsh() return ;; -s | --shell) - _shells "${chroot-}" + _comp_compgen_shells "${chroot-}" return ;; esac diff --git a/completions/_su b/completions/_su index 827fbdee0a6..3354447cbf5 100644 --- a/completions/_su +++ b/completions/_su @@ -15,7 +15,7 @@ _comp_cmd_su() case "$prev" in -s | --shell) - _shells + _comp_compgen_shells return ;; -c | --command | --session-command) diff --git a/completions/luseradd b/completions/luseradd index f541bbfeadc..255bc913561 100644 --- a/completions/luseradd +++ b/completions/luseradd @@ -18,7 +18,7 @@ _comp_cmd_luseradd() return ;; --shell | -${noargopts}s) - _shells + _comp_compgen_shells return ;; --gid | -${noargopts}g) diff --git a/completions/mussh b/completions/mussh index 488c25c8c43..9e76d35150c 100644 --- a/completions/mussh +++ b/completions/mussh @@ -30,7 +30,7 @@ _comp_cmd_mussh() return ;; -s) - _shells + _comp_compgen_shells return ;; -p | -h) diff --git a/completions/screen b/completions/screen index fffc98a88ae..28a7515b4c8 100644 --- a/completions/screen +++ b/completions/screen @@ -96,7 +96,7 @@ _comp_cmd_screen__sessions() return ;; -*s) - _shells + _comp_compgen_shells return ;; -*c) diff --git a/completions/useradd b/completions/useradd index 6c2bb0dd6bd..6c0bef1526c 100644 --- a/completions/useradd +++ b/completions/useradd @@ -42,7 +42,7 @@ _comp_cmd_useradd() return ;; --shell | -${noargopts}s) - _shells "${chroot-}" + _comp_compgen_shells "${chroot-}" return ;; esac diff --git a/completions/usermod b/completions/usermod index 6ff5a15f7fc..797e5368085 100644 --- a/completions/usermod +++ b/completions/usermod @@ -42,7 +42,7 @@ _comp_cmd_usermod() return ;; --shell | -${noargopts}s) - _shells "${chroot-}" + _comp_compgen_shells "${chroot-}" return ;; esac From 4d874574d4c581758324b30eef0f622af01c8643 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 02:10:54 +0900 Subject: [PATCH 06/11] refactor: rename `_{bash => }comp_try_faketty` --- bash_completion | 4 ++-- bash_completion.d/000_bash_completion_compat.bash | 1 + completions/postfix | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bash_completion b/bash_completion index 759a0d3c232..861b91cbe9d 100644 --- a/bash_completion +++ b/bash_completion @@ -2324,8 +2324,8 @@ _comp_compgen_terms() } 2>/dev/null)" } -# TODO:API: rename per conventions -_bashcomp_try_faketty() +# @since 2.12 +_comp_try_faketty() { if type unbuffer &>/dev/null; then unbuffer -p "$@" diff --git a/bash_completion.d/000_bash_completion_compat.bash b/bash_completion.d/000_bash_completion_compat.bash index 597c7e22f5b..3609e814c57 100644 --- a/bash_completion.d/000_bash_completion_compat.bash +++ b/bash_completion.d/000_bash_completion_compat.bash @@ -22,6 +22,7 @@ _comp_deprecate_func 2.12 _uids _comp_compgen_uids _comp_deprecate_func 2.12 _gids _comp_compgen_gids _comp_deprecate_func 2.12 _xinetd_services _comp_compgen_xinetd_services _comp_deprecate_func 2.12 _services _comp_compgen_services +_comp_deprecate_func 2.12 _bashcomp_try_faketty _comp_try_faketty _comp_deprecate_func 2.12 _expand _comp_expand _comp_deprecate_func 2.12 _pids _comp_compgen_pids _comp_deprecate_func 2.12 _pgids _comp_compgen_pgids diff --git a/completions/postfix b/completions/postfix index 2710f958c38..a05f71f588b 100644 --- a/completions/postfix +++ b/completions/postfix @@ -17,7 +17,7 @@ _comp_cmd_postfix() esac if [[ $cur == -* ]]; then - _comp_compgen_usage -c _bashcomp_try_faketty "$1" --help + _comp_compgen_usage -c _comp_try_faketty "$1" --help return fi From d3119216c5de651e39e1026d0e81faf8949d46f6 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 03:14:09 +0900 Subject: [PATCH 07/11] refactor: rename `{ => _comp_compgen}_known_hosts{_real => }` --- bash_completion | 58 ++++++++++--------- .../000_bash_completion_compat.bash | 1 + completions/_xm | 2 +- completions/arping | 2 +- completions/arpspoof | 4 +- completions/cancel | 2 +- completions/chromium-browser | 2 +- completions/chronyc | 6 +- completions/curl | 6 +- completions/dhclient | 2 +- completions/fio | 2 +- completions/freeciv | 2 +- completions/geoiplookup | 2 +- completions/gkrellm | 2 +- completions/hping2 | 4 +- completions/ifstat | 2 +- completions/influx | 2 +- completions/iperf | 2 +- completions/ipmitool | 2 +- completions/jps | 2 +- completions/ktutil | 2 +- completions/ldapsearch | 14 ++--- completions/ldapvi | 2 +- completions/lftp | 2 +- completions/links | 2 +- completions/medusa | 2 +- completions/munin-node-configure | 2 +- completions/munin-update | 2 +- completions/mussh | 2 +- completions/mysql | 2 +- completions/mysqladmin | 2 +- completions/nc | 4 +- completions/nmap | 4 +- completions/nslookup | 6 +- completions/ntpdate | 2 +- completions/openssl | 2 +- completions/ping | 2 +- completions/psql | 10 ++-- completions/puppet | 12 ++-- completions/rdesktop | 2 +- completions/reportbug | 2 +- completions/rsync | 2 +- completions/screen | 2 +- completions/ssh | 14 ++--- completions/ssh-copy-id | 2 +- completions/ssh-keygen | 4 +- completions/ssh-keyscan | 2 +- completions/sshfs | 2 +- completions/sshmitm | 2 +- completions/tracepath | 2 +- completions/vncviewer | 8 +-- completions/vpnc | 2 +- completions/webmitm | 2 +- completions/wget | 2 +- completions/wol | 2 +- completions/wsimport | 2 +- completions/xgamma | 2 +- completions/xhost | 6 +- .../.ssh/config_asterisk_1 | 0 .../.ssh/config_asterisk_2 | 0 .../.ssh/config_question_mark | 0 .../.ssh/config_relative_path | 0 .../config | 2 +- .../config_full_path | 0 .../config_include | 4 +- .../config_include_recursion | 0 test/fixtures/_known_hosts/config_tilde | 4 ++ .../gee-filename-canary | 0 .../known_hosts | 0 .../known_hosts2 | 0 .../known_hosts3 | 0 .../known_hosts4 | 0 test/fixtures/_known_hosts/localhost_config | 1 + .../localhost_hosts | 0 test/fixtures/_known_hosts/spaced conf | 8 +++ .../spaced known_hosts | 0 test/fixtures/_known_hosts_real/config_tilde | 4 -- .../_known_hosts_real/localhost_config | 1 - test/fixtures/_known_hosts_real/spaced conf | 8 --- test/t/conftest.py | 2 +- test/t/unit/Makefile.am | 2 +- ...hosts_real.py => test_unit_known_hosts.py} | 42 +++++++------- 82 files changed, 165 insertions(+), 158 deletions(-) rename test/fixtures/{_known_hosts_real => _known_hosts}/.ssh/config_asterisk_1 (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/.ssh/config_asterisk_2 (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/.ssh/config_question_mark (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/.ssh/config_relative_path (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/config (79%) rename test/fixtures/{_known_hosts_real => _known_hosts}/config_full_path (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/config_include (78%) rename test/fixtures/{_known_hosts_real => _known_hosts}/config_include_recursion (100%) create mode 100644 test/fixtures/_known_hosts/config_tilde rename test/fixtures/{_known_hosts_real => _known_hosts}/gee-filename-canary (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/known_hosts (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/known_hosts2 (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/known_hosts3 (100%) rename test/fixtures/{_known_hosts_real => _known_hosts}/known_hosts4 (100%) create mode 100644 test/fixtures/_known_hosts/localhost_config rename test/fixtures/{_known_hosts_real => _known_hosts}/localhost_hosts (100%) create mode 100644 test/fixtures/_known_hosts/spaced conf rename test/fixtures/{_known_hosts_real => _known_hosts}/spaced known_hosts (100%) delete mode 100644 test/fixtures/_known_hosts_real/config_tilde delete mode 100644 test/fixtures/_known_hosts_real/localhost_config delete mode 100644 test/fixtures/_known_hosts_real/spaced conf rename test/t/unit/{test_unit_known_hosts_real.py => test_unit_known_hosts.py} (78%) diff --git a/bash_completion b/bash_completion index 861b91cbe9d..432471cdf79 100644 --- a/bash_completion +++ b/bash_completion @@ -2351,7 +2351,7 @@ _user_at_host() _comp_initialize -n : -- "$@" || return if [[ $cur == *@* ]]; then - _known_hosts_real "$cur" + _comp_compgen_known_hosts "$cur" else _comp_compgen -- -u -S @ compopt -o nospace @@ -2360,20 +2360,21 @@ _user_at_host() shopt -u hostcomplete && complete -F _user_at_host talk ytalk finger # NOTE: Using this function as a helper function is deprecated. Use -# `_known_hosts_real' instead. +# `_comp_compgen_known_hosts' instead. # TODO:API: rename per conventions _known_hosts() { local cur prev words cword comp_args _comp_initialize -n : -- "$@" || return - # NOTE: Using `_known_hosts' as a helper function and passing options - # to `_known_hosts' is deprecated: Use `_known_hosts_real' instead. + # NOTE: Using `_known_hosts' as a helper function and passing options to + # `_known_hosts' is deprecated: Use `_comp_compgen_known_hosts' + # instead. local -a options=() [[ ${1-} == -a || ${2-} == -a ]] && options+=(-a) [[ ${1-} == -c || ${2-} == -c ]] && options+=(-c) local IFS=$' \t\n' # Workaround for connected ${v+"$@"} in bash < 4.4 - _known_hosts_real ${options[@]+"${options[@]}"} -- "$cur" + _comp_compgen_known_hosts ${options[@]+"${options[@]}"} -- "$cur" } # _known_hosts() # Helper function to locate ssh included files in configs @@ -2436,7 +2437,7 @@ _comp__included_ssh_config_files() # BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI is set to a non-empty value. # Also hosts from HOSTFILE (compgen -A hostname) are added, unless # BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value. -# Usage: _known_hosts_real [OPTIONS] CWORD +# Usage: _comp_compgen_known_hosts [OPTIONS] CWORD # Options: # -a Use aliases from ssh config files # -c Use `:' suffix @@ -2445,9 +2446,17 @@ _comp__included_ssh_config_files() # -4 Filter IPv6 addresses from results # -6 Filter IPv4 addresses from results # @return Completions, starting with CWORD, are added to COMPREPLY[] -# TODO:API: rename per conventions -_known_hosts_real() +# @since 2.12 +_comp_compgen_known_hosts() +{ + local known_hosts + _comp_compgen_known_hosts__impl "$@" || return "$?" + _comp_compgen -U known_hosts set "${known_hosts[@]}" +} +_comp_compgen_known_hosts__impl() { + known_hosts=() + local configfile="" flag prefix="" local cur suffix="" aliases="" i host ipv4="" ipv6="" local -a kh tmpkh=() khd=() config=() @@ -2550,8 +2559,6 @@ _known_hosts_real() # If we have known_hosts files to use if ((${#kh[@]} + ${#khd[@]} > 0)); then - local -a tmp=() - if ((${#kh[@]} > 0)); then # https://man.openbsd.org/sshd.8#SSH_KNOWN_HOSTS_FILE_FORMAT for i in "${kh[@]}"; do @@ -2573,7 +2580,7 @@ _known_hosts_real() # Remove trailing ] + optional :port host=${host%]?(:+([0-9]))} # Add host to candidates - [[ $host ]] && tmp+=("$host") + [[ $host ]] && known_hosts+=("$host") done fi done <"$i" @@ -2588,21 +2595,21 @@ _known_hosts_real() if [[ $i == *key_22_*.pub && -r $i ]]; then host=${i/#*key_22_/} host=${host/%.pub/} - [[ $host ]] && tmp+=("$host") + [[ $host ]] && known_hosts+=("$host") fi done fi # apply suffix and prefix - ((${#tmp[@]})) && - _comp_compgen -- -W '"${tmp[@]}"' -P "$prefix" -S "$suffix" + ((${#known_hosts[@]})) && + _comp_compgen -v known_hosts -- -W '"${known_hosts[@]}"' -P "$prefix" -S "$suffix" fi # append any available aliases from ssh config files if [[ ${#config[@]} -gt 0 && $aliases ]]; then local -a hosts if _comp_split hosts "$(command sed -ne 's/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]=]\{1,\}\(.*\)$/\1/p' "${config[@]}")"; then - _comp_compgen -a -- -P "$prefix" \ + _comp_compgen -av known_hosts -- -P "$prefix" \ -S "$suffix" -W '"${hosts[@]%%[*?%]*}"' -X '@(\!*|)' fi fi @@ -2615,38 +2622,37 @@ _known_hosts_real() local generated=$(avahi-browse -cprak 2>/dev/null | awk -F';' \ '/^=/ && $5 ~ /^_(ssh|workstation)\._tcp$/ { print $7 }' | sort -u) - _comp_compgen -a -- -P "$prefix" -S "$suffix" -W '$generated' + _comp_compgen -av known_hosts -- -P "$prefix" -S "$suffix" -W '$generated' fi # Add hosts reported by ruptime. if type ruptime &>/dev/null; then local generated=$(ruptime 2>/dev/null | awk '!/^ruptime:/ { print $1 }') - _comp_compgen -a -- -W '$generated' + _comp_compgen -av known_hosts -- -W '$generated' fi # Add results of normal hostname completion, unless # `BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value. if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}} ]]; then - _comp_compgen -a -- -A hostname -P "$prefix" -S "$suffix" + _comp_compgen -av known_hosts -- -A hostname -P "$prefix" -S "$suffix" fi - if ((${#COMPREPLY[@]})); then + if ((${#known_hosts[@]})); then if [[ $ipv4 ]]; then - COMPREPLY=("${COMPREPLY[@]/*:*$suffix/}") + known_hosts=("${known_hosts[@]/*:*$suffix/}") fi if [[ $ipv6 ]]; then - COMPREPLY=("${COMPREPLY[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}") + known_hosts=("${known_hosts[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}") fi if [[ $ipv4 || $ipv6 ]]; then - for i in "${!COMPREPLY[@]}"; do - [[ ${COMPREPLY[i]} ]] || unset -v 'COMPREPLY[i]' + for i in "${!known_hosts[@]}"; do + [[ ${known_hosts[i]} ]] || unset -v 'known_hosts[i]' done fi + _comp_compgen -v known_hosts -c "$prefix$cur" ltrim_colon "${known_hosts[@]}" fi - _comp_ltrim_colon_completions "$prefix$cur" - -} # _known_hosts_real() +} # _comp_compgen_known_hosts__impl() complete -F _known_hosts traceroute traceroute6 \ fping fping6 telnet rsh rlogin ftp dig drill mtr ssh-installkeys showmount diff --git a/bash_completion.d/000_bash_completion_compat.bash b/bash_completion.d/000_bash_completion_compat.bash index 3609e814c57..0d9730fff4b 100644 --- a/bash_completion.d/000_bash_completion_compat.bash +++ b/bash_completion.d/000_bash_completion_compat.bash @@ -10,6 +10,7 @@ _comp_deprecate_func 2.12 _root_command _comp_root_command _comp_deprecate_func 2.12 _xfunc _comp_xfunc _comp_deprecate_func 2.12 _upvars _comp_upvars _comp_deprecate_func 2.12 _get_comp_words_by_ref _comp_get_words +_comp_deprecate_func 2.12 _known_hosts_real _comp_compgen_known_hosts _comp_deprecate_func 2.12 _longopt _comp_longopt _comp_deprecate_func 2.12 __ltrim_colon_completions _comp_ltrim_colon_completions _comp_deprecate_func 2.12 _signals _comp_compgen_signals diff --git a/completions/_xm b/completions/_xm index a79c74c1003..ff92220aa85 100644 --- a/completions/_xm +++ b/completions/_xm @@ -93,7 +93,7 @@ _comp_cmd_xm() _comp_cmd_xm__domain_names ;; 3) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" ;; esac ;; diff --git a/completions/arping b/completions/arping index 693144df2f6..c69fc2d266d 100644 --- a/completions/arping +++ b/completions/arping @@ -24,7 +24,7 @@ _comp_cmd_arping() return fi - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" } && complete -F _comp_cmd_arping arping diff --git a/completions/arpspoof b/completions/arpspoof index 85c2145fbaf..8939f2d5ed4 100644 --- a/completions/arpspoof +++ b/completions/arpspoof @@ -11,7 +11,7 @@ _comp_cmd_arpspoof() return ;; -t) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; esac @@ -19,7 +19,7 @@ _comp_cmd_arpspoof() if [[ $cur == -* ]]; then _comp_compgen_usage else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && diff --git a/completions/cancel b/completions/cancel index 64770453a41..38571c50979 100644 --- a/completions/cancel +++ b/completions/cancel @@ -7,7 +7,7 @@ _comp_cmd_cancel() case $prev in -h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -U) diff --git a/completions/chromium-browser b/completions/chromium-browser index ac9a83f60e2..1f0bb082007 100644 --- a/completions/chromium-browser +++ b/completions/chromium-browser @@ -17,7 +17,7 @@ _comp_cmd_chromium_browser() case $cur in *://*) local prefix="${cur%%://*}://" - _known_hosts_real -- "${cur#*://}" + _comp_compgen_known_hosts -- "${cur#*://}" COMPREPLY=("${COMPREPLY[@]/#/$prefix}") _comp_ltrim_colon_completions "$cur" ;; diff --git a/completions/chronyc b/completions/chronyc index 000a747de40..b6bca0089e5 100644 --- a/completions/chronyc +++ b/completions/chronyc @@ -6,7 +6,7 @@ _comp_cmd_chronyc__command_args() _comp_split args "$("$1" help 2>/dev/null | awk '/^'"$prev"'\s[^ []/ { gsub("\\|", " ", $2); print $2 }')" case $args in - \) _known_hosts_real -- "$cur" ;; + \) _comp_compgen_known_hosts -- "$cur" ;; \<*) ;; *) ((${#args[@]})) && _comp_compgen -a -- -W '"${args[@]}"' ;; @@ -23,7 +23,7 @@ _comp_cmd_chronyc() return ;; -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; esac @@ -53,7 +53,7 @@ _comp_cmd_chronyc() fi ;; 2) - [[ $prev == @(peer|server) ]] && _known_hosts_real -- "$cur" + [[ $prev == @(peer|server) ]] && _comp_compgen_known_hosts -- "$cur" ;; esac } && diff --git a/completions/curl b/completions/curl index 7b9124f896c..4b85bd566a7 100644 --- a/completions/curl +++ b/completions/curl @@ -71,7 +71,7 @@ _comp_cmd_curl() return ;; --dns-servers | --noproxy) - _known_hosts_real -- "${cur##*,}" + _comp_compgen_known_hosts -- "${cur##*,}" ((${#COMPREPLY[@]})) && _comp_delimited , -W '"${COMPREPLY[@]}"' return @@ -86,7 +86,7 @@ _comp_cmd_curl() ;; --ftp-port | -${noargopts}P) _comp_compgen_available_interfaces -a - _known_hosts_real -- "$cur" + _comp_compgen -a known_hosts -- "$cur" _comp_compgen -a ip_addresses -a return ;; @@ -126,7 +126,7 @@ _comp_cmd_curl() ;; --preproxy | --proxy | --socks4 | --socks4a | --socks5 | \ --socks5-hostname | -${noargopts}x) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --pubkey) diff --git a/completions/dhclient b/completions/dhclient index d614859a0e9..330a29850ef 100644 --- a/completions/dhclient +++ b/completions/dhclient @@ -18,7 +18,7 @@ _comp_cmd_dhclient() return ;; -s) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; esac diff --git a/completions/fio b/completions/fio index 020db2ee376..f05518eddf0 100644 --- a/completions/fio +++ b/completions/fio @@ -54,7 +54,7 @@ _comp_cmd_fio() return ;; --client) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --remote-config) diff --git a/completions/freeciv b/completions/freeciv index 771e9f5e283..2dedf37f76b 100644 --- a/completions/freeciv +++ b/completions/freeciv @@ -22,7 +22,7 @@ _comp_cmd_freeciv() return ;; --Meta | --server | -[Ms]) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --Plugin | -P) diff --git a/completions/geoiplookup b/completions/geoiplookup index 904d03db791..504c22a06c0 100644 --- a/completions/geoiplookup +++ b/completions/geoiplookup @@ -26,7 +26,7 @@ _comp_cmd_geoiplookup() local ipvx [[ $1 == *6 ]] && ipvx=-6 || ipvx=-4 - _known_hosts_real $ipvx -- "$cur" + _comp_compgen_known_hosts $ipvx -- "$cur" } && complete -F _comp_cmd_geoiplookup geoiplookup geoiplookup6 diff --git a/completions/gkrellm b/completions/gkrellm index f8440d2e0ea..81781fb0a6a 100644 --- a/completions/gkrellm +++ b/completions/gkrellm @@ -15,7 +15,7 @@ _comp_cmd_gkrellm() return ;; -s | --server) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -l | --logfile) diff --git a/completions/hping2 b/completions/hping2 index 0b684b1441e..66139a905d0 100644 --- a/completions/hping2 +++ b/completions/hping2 @@ -13,7 +13,7 @@ _comp_cmd_hping2() return ;; --spoof | -${noargopts}a) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --tos | -${noargopts}o) @@ -30,7 +30,7 @@ _comp_cmd_hping2() if [[ $cur == -* ]]; then _comp_compgen_help else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && complete -F _comp_cmd_hping2 hping hping2 hping3 diff --git a/completions/ifstat b/completions/ifstat index 7981e4c0892..04f9b352c0f 100644 --- a/completions/ifstat +++ b/completions/ifstat @@ -35,7 +35,7 @@ _comp_cmd_ifstat() "$1" --help 2>&1 || : } | command grep -q -- '-s.*--noupdate'; then - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return fi ;; diff --git a/completions/influx b/completions/influx index a1ea806144d..4cf31f8c5a6 100644 --- a/completions/influx +++ b/completions/influx @@ -10,7 +10,7 @@ _comp_cmd_influx() return ;; -host) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -format | -precision | -consistency) diff --git a/completions/iperf b/completions/iperf index 78934af1166..6f63bf36859 100644 --- a/completions/iperf +++ b/completions/iperf @@ -44,7 +44,7 @@ _comp_cmd_iperf() return ;; --client | -${noargopts}c) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --reportexclude | -${noargopts}x) diff --git a/completions/ipmitool b/completions/ipmitool index 28ab7c6ad53..cc8c19d8f83 100644 --- a/completions/ipmitool +++ b/completions/ipmitool @@ -29,7 +29,7 @@ _comp_cmd_ipmitool() return ;; -*H) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*[fSO]) diff --git a/completions/jps b/completions/jps index be5b8d62151..324ba0ea095 100644 --- a/completions/jps +++ b/completions/jps @@ -17,7 +17,7 @@ _comp_cmd_jps() _comp_compgen -- -W "-q -m -l -v -V -J -help" [[ ${COMPREPLY-} == -J* ]] && compopt -o nospace else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && complete -F _comp_cmd_jps jps diff --git a/completions/ktutil b/completions/ktutil index 3d4dd401ae1..461a087bdd7 100644 --- a/completions/ktutil +++ b/completions/ktutil @@ -35,7 +35,7 @@ _comp_cmd_ktutil() return ;; -a | --admin-server) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -r | --realm) diff --git a/completions/ldapsearch b/completions/ldapsearch index 7311f4bd36d..71c728e20af 100644 --- a/completions/ldapsearch +++ b/completions/ldapsearch @@ -17,7 +17,7 @@ _comp_cmd_ldapsearch() case $prev in -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*H) @@ -60,7 +60,7 @@ _comp_cmd_ldapadd() case $prev in -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*H) @@ -91,7 +91,7 @@ _comp_cmd_ldapdelete() case $prev in -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*H) @@ -122,7 +122,7 @@ _comp_cmd_ldapcompare() case $prev in -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*H) @@ -153,7 +153,7 @@ _comp_cmd_ldapmodrdn() case $prev in -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*H) @@ -184,7 +184,7 @@ _comp_cmd_ldapwhoami() case $prev in -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*H) @@ -215,7 +215,7 @@ _comp_cmd_ldappasswd() case $prev in -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*H) diff --git a/completions/ldapvi b/completions/ldapvi index c0c57052f8f..d86cf55ca99 100644 --- a/completions/ldapvi +++ b/completions/ldapvi @@ -9,7 +9,7 @@ _comp_cmd_ldapvi() # shellcheck disable=SC2254 case $prev in --host | -${noargopts}h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --sasl-mech | -${noargopts}Y) diff --git a/completions/lftp b/completions/lftp index 7a8801e7487..16264cfcfd8 100644 --- a/completions/lftp +++ b/completions/lftp @@ -23,7 +23,7 @@ _comp_cmd_lftp() fi _comp_compgen_split -- "$("$1" -c "bookmark list" 2>/dev/null)" - _known_hosts_real -- "$cur" + _comp_compgen -a known_hosts -- "$cur" } && complete -F _comp_cmd_lftp lftp diff --git a/completions/links b/completions/links index ffc0bc52618..eb2d3028933 100644 --- a/completions/links +++ b/completions/links @@ -23,7 +23,7 @@ _comp_cmd_links() return ;; -lookup) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -driver) diff --git a/completions/medusa b/completions/medusa index 6c588f38539..33ca58eabc6 100644 --- a/completions/medusa +++ b/completions/medusa @@ -7,7 +7,7 @@ _comp_cmd_medusa() case $prev in -*h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*[HUPCO]) diff --git a/completions/munin-node-configure b/completions/munin-node-configure index c57814c74f2..edfb4b99e77 100644 --- a/completions/munin-node-configure +++ b/completions/munin-node-configure @@ -15,7 +15,7 @@ _comp_cmd_munin_node_configure() return ;; --snmp) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --snmpversion) diff --git a/completions/munin-update b/completions/munin-update index ecb8643667f..8ed8a1fb751 100644 --- a/completions/munin-update +++ b/completions/munin-update @@ -11,7 +11,7 @@ _comp_cmd_munin_update() return ;; --host) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; esac diff --git a/completions/mussh b/completions/mussh index 9e76d35150c..29cf4b925fe 100644 --- a/completions/mussh +++ b/completions/mussh @@ -34,7 +34,7 @@ _comp_cmd_mussh() return ;; -p | -h) - [[ $cur == *@* ]] && _user_at_host "$@" || _known_hosts_real -a -- "$cur" + [[ $cur == *@* ]] && _user_at_host "$@" || _comp_compgen_known_hosts -a -- "$cur" return ;; -c) diff --git a/completions/mysql b/completions/mysql index bb0d95d7115..dcd2d2acae9 100644 --- a/completions/mysql +++ b/completions/mysql @@ -37,7 +37,7 @@ _comp_cmd_mysql() ;; --host | -${noargopts}h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --default-character-set) diff --git a/completions/mysqladmin b/completions/mysqladmin index dbf95f1a851..df030266df3 100644 --- a/completions/mysqladmin +++ b/completions/mysqladmin @@ -13,7 +13,7 @@ _comp_cmd_mysqladmin() return ;; --host | -${noargopts}h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --character-sets-dir | --ssl-capath) diff --git a/completions/nc b/completions/nc index c4a3e4d4cd8..8fb1617faee 100644 --- a/completions/nc +++ b/completions/nc @@ -27,7 +27,7 @@ _comp_cmd_nc() return ;; -*x) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; esac @@ -42,7 +42,7 @@ _comp_cmd_nc() _comp_count_args -n "" -a "-*[IiMmOPpqsTVWwXx]" ((ret == 1)) || return - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" } && complete -F _comp_cmd_nc nc diff --git a/completions/nmap b/completions/nmap index 4046c8e2d3e..a3e691b05cd 100644 --- a/completions/nmap +++ b/completions/nmap @@ -19,7 +19,7 @@ _comp_cmd_nmap() return ;; -b | --dns-servers) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; esac @@ -47,7 +47,7 @@ _comp_cmd_nmap() )" [[ ${COMPREPLY-} == *= ]] && compopt -o nospace else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && complete -F _comp_cmd_nmap nmap diff --git a/completions/nslookup b/completions/nslookup index 553e4001e3e..9179da75aeb 100644 --- a/completions/nslookup +++ b/completions/nslookup @@ -55,7 +55,7 @@ _comp_cmd_nslookup() local ret _comp_count_args if ((ret <= 2)); then - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" [[ $ret -eq 1 && $cur == @(|-) ]] && COMPREPLY+=(-) fi } && @@ -92,12 +92,12 @@ _comp_cmd_host() local ret _comp_count_args -a "-*[ctmNRW]" if ((ret == 1)); then - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" elif ((ret == 2)); then local ipvx [[ ${words[*]} =~ \ -[^\ ]*([46]) ]] && ipvx=-${BASH_REMATCH[1]} # shellcheck disable=SC2086 - _known_hosts_real ${ipvx-} -- "$cur" + _comp_compgen_known_hosts ${ipvx-} -- "$cur" fi } && complete -F _comp_cmd_host host diff --git a/completions/ntpdate b/completions/ntpdate index 594065c692b..5dab0a7c0b7 100644 --- a/completions/ntpdate +++ b/completions/ntpdate @@ -27,7 +27,7 @@ _comp_cmd_ntpdate() if [[ $cur == -* ]]; then _comp_compgen_help -- -h || _comp_compgen_usage else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && complete -F _comp_cmd_ntpdate ntpdate diff --git a/completions/openssl b/completions/openssl index 808500aaad2..a4429259af2 100644 --- a/completions/openssl +++ b/completions/openssl @@ -96,7 +96,7 @@ _comp_cmd_openssl() return ;; -connect) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -starttls) diff --git a/completions/ping b/completions/ping index 103ee33dfb2..44c088852c2 100644 --- a/completions/ping +++ b/completions/ping @@ -64,7 +64,7 @@ _comp_cmd_ping() [[ $1 == *6 ]] && ipvx=-6 [[ $1 == *4 ]] && ipvx=-4 - _known_hosts_real ${ipvx-} -- "$cur" + _comp_compgen_known_hosts ${ipvx-} -- "$cur" } && complete -F _comp_cmd_ping ping ping4 ping6 diff --git a/completions/psql b/completions/psql index 206e34b7e66..073c5725cf0 100644 --- a/completions/psql +++ b/completions/psql @@ -27,7 +27,7 @@ _comp_cmd_createdb() # shellcheck disable=SC2254 case $prev in --host | -${noargopts}h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --username | --owner | -${noargopts}[UO]) @@ -65,7 +65,7 @@ _comp_cmd_createuser() return ;; --host | -${noargopts}h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --username | -${noargopts}U) @@ -94,7 +94,7 @@ _comp_cmd_dropdb() # shellcheck disable=SC2254 case $prev in --host | -${noargopts}h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --username | -${noargopts}U) @@ -131,7 +131,7 @@ _comp_cmd_dropuser() return ;; --host | -${noargopts}h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --username | -${noargopts}U) @@ -162,7 +162,7 @@ _comp_cmd_psql() # shellcheck disable=SC2254 case $prev in --host | -${noargopts}h) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --username | -${noargopts}U) diff --git a/completions/puppet b/completions/puppet index 91b8341e719..0bde46f513c 100644 --- a/completions/puppet +++ b/completions/puppet @@ -122,7 +122,7 @@ _comp_cmd_puppet() agent) case $prev in --certname) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --digest) @@ -130,7 +130,7 @@ _comp_cmd_puppet() return ;; --fqdn) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -l | --logdest) @@ -196,7 +196,7 @@ _comp_cmd_puppet() return ;; generate | --generate) - _known_hosts_real -- "$cur" + _comp_compgen -a known_hosts -- "$cur" return ;; clean | print | revoke | --clean | --print | --revoke) @@ -251,7 +251,7 @@ _comp_cmd_puppet() filebucket) case $prev in -s | --server) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -b | --bucket) @@ -275,7 +275,7 @@ _comp_cmd_puppet() return ;; --host) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -t | --tag) @@ -285,7 +285,7 @@ _comp_cmd_puppet() if [[ $cur == -* ]]; then _comp_cmd_puppet__subcmd_opts "$1" "$subcommand" else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi return ;; diff --git a/completions/rdesktop b/completions/rdesktop index ce169c5c54d..f03b05119af 100644 --- a/completions/rdesktop +++ b/completions/rdesktop @@ -50,7 +50,7 @@ _comp_cmd_rdesktop() ((${#opts[@]})) && _comp_compgen -- -W '"${opts[@]%:}"' else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && diff --git a/completions/reportbug b/completions/reportbug index c806b8dce64..2c731d881fc 100644 --- a/completions/reportbug +++ b/completions/reportbug @@ -46,7 +46,7 @@ _comp_cmd_reportbug() return ;; --smtphost) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --draftpath) diff --git a/completions/rsync b/completions/rsync index 24f0d77ddaf..c614987918e 100644 --- a/completions/rsync +++ b/completions/rsync @@ -84,7 +84,7 @@ _comp_cmd_rsync() [[ $shell == ssh ]] && _comp_compgen -x scp remote_files ;; *) - _known_hosts_real -c -a -- "$cur" + _comp_compgen_known_hosts -c -a -- "$cur" _comp_xfunc scp local_files ;; esac diff --git a/completions/screen b/completions/screen index 28a7515b4c8..8409dfc7f0b 100644 --- a/completions/screen +++ b/completions/screen @@ -49,7 +49,7 @@ _comp_cmd_screen__sessions() return ;; //telnet) - ((cword == 2)) && _known_hosts_real -- "$cur" + ((cword == 2)) && _comp_compgen_known_hosts -- "$cur" return ;; esac diff --git a/completions/ssh b/completions/ssh index d324cde2148..d88d028f56e 100644 --- a/completions/ssh +++ b/completions/ssh @@ -199,7 +199,7 @@ _comp_cmd_ssh__suboption() fi ;; proxyjump) - _known_hosts_real -a ${configfile:+-F "$configfile"} -- "$cur" + _comp_compgen_known_hosts -a ${configfile:+-F "$configfile"} -- "$cur" ;; proxycommand | remotecommand | localcommand) _comp_compgen_commands @@ -331,7 +331,7 @@ _comp_cmd_ssh() return ;; -*J) - _known_hosts_real -a ${configfile:+-F "$configfile"} -- "$cur" + _comp_compgen_known_hosts -a ${configfile:+-F "$configfile"} -- "$cur" return ;; -*l) @@ -380,7 +380,7 @@ _comp_cmd_ssh() compopt -o filenames _comp_compgen_commands else - _known_hosts_real ${ipvx-} -a ${configfile:+-F "$configfile"} \ + _comp_compgen_known_hosts ${ipvx-} -a ${configfile:+-F "$configfile"} \ -- "$cur" fi fi @@ -423,7 +423,7 @@ _comp_cmd_sftp() return ;; -*J) - _known_hosts_real -a ${configfile:+-F "$configfile"} -- "$cur" + _comp_compgen_known_hosts -a ${configfile:+-F "$configfile"} -- "$cur" return ;; -*o) @@ -449,7 +449,7 @@ _comp_cmd_sftp() elif [[ $cur == -* ]]; then _comp_compgen_usage else - _known_hosts_real ${ipvx:+"$ipvx"} -a ${configfile:+-F "$configfile"} -- "$cur" + _comp_compgen_known_hosts ${ipvx:+"$ipvx"} -a ${configfile:+-F "$configfile"} -- "$cur" fi } && shopt -u hostcomplete && complete -F _comp_cmd_sftp sftp @@ -574,7 +574,7 @@ _comp_cmd_scp() return ;; -*J) - _known_hosts_real -a ${configfile:+-F "$configfile"} -- "$cur" + _comp_compgen_known_hosts -a ${configfile:+-F "$configfile"} -- "$cur" return ;; -*[lP]) @@ -621,7 +621,7 @@ _comp_cmd_scp() ;; *) if ! _comp_looks_like_path "$cur"; then - _known_hosts_real ${ipvx-} -c -a \ + _comp_compgen_known_hosts ${ipvx-} -c -a \ ${configfile:+-F "$configfile"} -- "$cur" fi ;; diff --git a/completions/ssh-copy-id b/completions/ssh-copy-id index ff13012c696..59b96db3a25 100644 --- a/completions/ssh-copy-id +++ b/completions/ssh-copy-id @@ -28,7 +28,7 @@ _comp_cmd_ssh_copy_id() if [[ $cur == -* ]]; then _comp_compgen_usage -- --help else - _known_hosts_real -a -- "$cur" + _comp_compgen_known_hosts -a -- "$cur" fi } && complete -F _comp_cmd_ssh_copy_id ssh-copy-id diff --git a/completions/ssh-keygen b/completions/ssh-keygen index bd13b55692f..3f9d17572b4 100644 --- a/completions/ssh-keygen +++ b/completions/ssh-keygen @@ -32,7 +32,7 @@ _comp_cmd_ssh_keygen() ;; -*[FR]) # TODO: trim this down to actual entries in known hosts files - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; -*[Dw]) @@ -50,7 +50,7 @@ _comp_cmd_ssh_keygen() -*n) [[ ${words[*]} != *\ -*Y\ * ]] || return if [[ ${words[*]} == *\ -*h\ * ]]; then - _known_hosts_real -- "${cur##*,}" + _comp_compgen_known_hosts -- "${cur##*,}" ((${#COMPREPLY[@]})) && _comp_delimited , -W '"${COMPREPLY[@]}"' else diff --git a/completions/ssh-keyscan b/completions/ssh-keyscan index f88c13a7dbf..f5e436494dd 100644 --- a/completions/ssh-keyscan +++ b/completions/ssh-keyscan @@ -32,7 +32,7 @@ _comp_cmd_ssh_keyscan() return fi - _known_hosts_real ${ipvx-} -- "$cur" + _comp_compgen_known_hosts ${ipvx-} -- "$cur" } && complete -F _comp_cmd_ssh_keyscan ssh-keyscan diff --git a/completions/sshfs b/completions/sshfs index 21d0be442b5..de0bea0aa22 100644 --- a/completions/sshfs +++ b/completions/sshfs @@ -14,7 +14,7 @@ _comp_cmd_sshfs() return fi - [[ $cur == @(*/|[.~])* ]] || _known_hosts_real -c -a -- "$cur" + [[ $cur == @(*/|[.~])* ]] || _comp_compgen_known_hosts -c -a -- "$cur" _comp_xfunc scp local_files -d } && diff --git a/completions/sshmitm b/completions/sshmitm index 4b14301f574..136d2f989e6 100644 --- a/completions/sshmitm +++ b/completions/sshmitm @@ -8,7 +8,7 @@ _comp_cmd_sshmitm() if [[ $cur == -* ]]; then _comp_compgen_usage else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && diff --git a/completions/tracepath b/completions/tracepath index f6a57db289d..d8269bdd888 100644 --- a/completions/tracepath +++ b/completions/tracepath @@ -18,7 +18,7 @@ _comp_cmd_tracepath() local ipvx [[ $1 == *6 ]] && ipvx=-6 - _known_hosts_real ${ipvx-} -- "$cur" + _comp_compgen_known_hosts ${ipvx-} -- "$cur" } && complete -F _comp_cmd_tracepath tracepath tracepath6 diff --git a/completions/vncviewer b/completions/vncviewer index 83014b97d6d..e1b146fdd3c 100644 --- a/completions/vncviewer +++ b/completions/vncviewer @@ -32,7 +32,7 @@ _comp_cmd_tightvncviewer() return ;; -via) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; esac @@ -43,7 +43,7 @@ _comp_cmd_tightvncviewer() -truecolour -truecolor -depth -compresslevel -quality -nojpeg -nocursorshape -x11cursor' else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && complete -F _comp_cmd_tightvncviewer tightvncviewer @@ -68,7 +68,7 @@ _comp_cmd_xvnc4viewer() return ;; -via) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; esac @@ -91,7 +91,7 @@ _comp_cmd_xvnc4viewer() done)) $reset else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && complete -F _comp_cmd_xvnc4viewer xvnc4viewer diff --git a/completions/vpnc b/completions/vpnc index dca6236f1c9..1a81f188cf9 100644 --- a/completions/vpnc +++ b/completions/vpnc @@ -12,7 +12,7 @@ _comp_cmd_vpnc() return ;; --gateway) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --vendor) diff --git a/completions/webmitm b/completions/webmitm index c56208eeb69..df6faa2b106 100644 --- a/completions/webmitm +++ b/completions/webmitm @@ -8,7 +8,7 @@ _comp_cmd_webmitm() if [[ $cur == -* ]]; then _comp_compgen_usage else - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" fi } && diff --git a/completions/wget b/completions/wget index 8045a8a63f6..5e0f08b8b7d 100644 --- a/completions/wget +++ b/completions/wget @@ -20,7 +20,7 @@ _comp_cmd_wget() return ;; --domains | --exclude-domains | -${noargopts}D) - _known_hosts_real -- "$cur" + _comp_compgen_known_hosts -- "$cur" return ;; --restrict-file-names) diff --git a/completions/wol b/completions/wol index 932ed5686ae..48c548f794d 100644 --- a/completions/wol +++ b/completions/wol @@ -21,7 +21,7 @@ _comp_cmd_wol() -ne 's/.*[[:space:]]Bcast:\([^[:space:]]*\).*/\1/p' \ -ne 's/.*inet.*[[:space:]]brd[[:space:]]\([^[:space:]]*\).*/\1/p' \ -ne 's/.*[[:space:]]broadcast[[:space:]]\{1,\}\([^[:space:]]*\).*/\1/p')) - _known_hosts_real -- "$cur" + _comp_compgen -a known_hosts -- "$cur" return ;; --file | -${noargopts}f) diff --git a/completions/wsimport b/completions/wsimport index 19650563f09..cee8c09f416 100644 --- a/completions/wsimport +++ b/completions/wsimport @@ -32,7 +32,7 @@ _comp_cmd_wsimport() esac if [[ $cur == -httpproxy:* ]]; then - _known_hosts_real -- "${cur#-httpproxy:}" + _comp_compgen_known_hosts -- "${cur#-httpproxy:}" return elif [[ $cur == -* ]]; then _comp_compgen_help -- -help diff --git a/completions/xgamma b/completions/xgamma index 19794098666..2a0c40973f5 100644 --- a/completions/xgamma +++ b/completions/xgamma @@ -36,7 +36,7 @@ _comp_cmd_xgamma() _comp_compgen -c "${cur##*.}" -- -P "${t%.*}." -W '$screens' elif [[ $cur != *:* ]]; then # complete hostnames - _known_hosts_real -c -- "$cur" + _comp_compgen_known_hosts -c -- "$cur" if [[ ! $cur ]]; then COMPREPLY+=(:) fi diff --git a/completions/xhost b/completions/xhost index 63be8845d5d..9491030b23e 100644 --- a/completions/xhost +++ b/completions/xhost @@ -6,9 +6,9 @@ _comp_cmd_xhost() _comp_initialize -- "$@" || return case $cur in - +*) _known_hosts_real -p+ -- "${cur:1}" ;; - -*) _known_hosts_real -p- -- "${cur:1}" ;; - *) _known_hosts_real -- "$cur" ;; + +*) _comp_compgen_known_hosts -p+ -- "${cur:1}" ;; + -*) _comp_compgen_known_hosts -p- -- "${cur:1}" ;; + *) _comp_compgen_known_hosts -- "$cur" ;; esac } && complete -F _comp_cmd_xhost xhost diff --git a/test/fixtures/_known_hosts_real/.ssh/config_asterisk_1 b/test/fixtures/_known_hosts/.ssh/config_asterisk_1 similarity index 100% rename from test/fixtures/_known_hosts_real/.ssh/config_asterisk_1 rename to test/fixtures/_known_hosts/.ssh/config_asterisk_1 diff --git a/test/fixtures/_known_hosts_real/.ssh/config_asterisk_2 b/test/fixtures/_known_hosts/.ssh/config_asterisk_2 similarity index 100% rename from test/fixtures/_known_hosts_real/.ssh/config_asterisk_2 rename to test/fixtures/_known_hosts/.ssh/config_asterisk_2 diff --git a/test/fixtures/_known_hosts_real/.ssh/config_question_mark b/test/fixtures/_known_hosts/.ssh/config_question_mark similarity index 100% rename from test/fixtures/_known_hosts_real/.ssh/config_question_mark rename to test/fixtures/_known_hosts/.ssh/config_question_mark diff --git a/test/fixtures/_known_hosts_real/.ssh/config_relative_path b/test/fixtures/_known_hosts/.ssh/config_relative_path similarity index 100% rename from test/fixtures/_known_hosts_real/.ssh/config_relative_path rename to test/fixtures/_known_hosts/.ssh/config_relative_path diff --git a/test/fixtures/_known_hosts_real/config b/test/fixtures/_known_hosts/config similarity index 79% rename from test/fixtures/_known_hosts_real/config rename to test/fixtures/_known_hosts/config index 85f06790af9..fad532b58f5 100644 --- a/test/fixtures/_known_hosts_real/config +++ b/test/fixtures/_known_hosts/config @@ -1,4 +1,4 @@ - UserKnownHostsFile _known_hosts_real/known_hosts + UserKnownHostsFile _known_hosts/known_hosts # Unindented Host * diff --git a/test/fixtures/_known_hosts_real/config_full_path b/test/fixtures/_known_hosts/config_full_path similarity index 100% rename from test/fixtures/_known_hosts_real/config_full_path rename to test/fixtures/_known_hosts/config_full_path diff --git a/test/fixtures/_known_hosts_real/config_include b/test/fixtures/_known_hosts/config_include similarity index 78% rename from test/fixtures/_known_hosts_real/config_include rename to test/fixtures/_known_hosts/config_include index d54f3ee56bf..d68b0d81597 100644 --- a/test/fixtures/_known_hosts_real/config_include +++ b/test/fixtures/_known_hosts/config_include @@ -1,4 +1,4 @@ -#$HOME set to fixtures/_known_hosts_real in unit test +#$HOME set to fixtures/_known_hosts in unit test # Include with full path (recursive one) Include ~/config_full_path # Include with relative path @@ -6,4 +6,4 @@ Include config_relative_path # Include with wildcards, and more than one on same row Include config_asterisk* config_?uestion_mark # Include a directory name. This is a misconfiguration, but ssh ignores it without errors. -Include ../../_known_hosts_real +Include ../../_known_hosts diff --git a/test/fixtures/_known_hosts_real/config_include_recursion b/test/fixtures/_known_hosts/config_include_recursion similarity index 100% rename from test/fixtures/_known_hosts_real/config_include_recursion rename to test/fixtures/_known_hosts/config_include_recursion diff --git a/test/fixtures/_known_hosts/config_tilde b/test/fixtures/_known_hosts/config_tilde new file mode 100644 index 00000000000..93e495b0d72 --- /dev/null +++ b/test/fixtures/_known_hosts/config_tilde @@ -0,0 +1,4 @@ +# With quotes and tilde, and = +UserKnownHostsFile = "~/_known_hosts/known_hosts2" +# Without quotes, with tilde, and another on the same line +UserKnownHostsFile ~/_known_hosts/known_hosts3 _known_hosts/known_hosts4 diff --git a/test/fixtures/_known_hosts_real/gee-filename-canary b/test/fixtures/_known_hosts/gee-filename-canary similarity index 100% rename from test/fixtures/_known_hosts_real/gee-filename-canary rename to test/fixtures/_known_hosts/gee-filename-canary diff --git a/test/fixtures/_known_hosts_real/known_hosts b/test/fixtures/_known_hosts/known_hosts similarity index 100% rename from test/fixtures/_known_hosts_real/known_hosts rename to test/fixtures/_known_hosts/known_hosts diff --git a/test/fixtures/_known_hosts_real/known_hosts2 b/test/fixtures/_known_hosts/known_hosts2 similarity index 100% rename from test/fixtures/_known_hosts_real/known_hosts2 rename to test/fixtures/_known_hosts/known_hosts2 diff --git a/test/fixtures/_known_hosts_real/known_hosts3 b/test/fixtures/_known_hosts/known_hosts3 similarity index 100% rename from test/fixtures/_known_hosts_real/known_hosts3 rename to test/fixtures/_known_hosts/known_hosts3 diff --git a/test/fixtures/_known_hosts_real/known_hosts4 b/test/fixtures/_known_hosts/known_hosts4 similarity index 100% rename from test/fixtures/_known_hosts_real/known_hosts4 rename to test/fixtures/_known_hosts/known_hosts4 diff --git a/test/fixtures/_known_hosts/localhost_config b/test/fixtures/_known_hosts/localhost_config new file mode 100644 index 00000000000..3c6a2095296 --- /dev/null +++ b/test/fixtures/_known_hosts/localhost_config @@ -0,0 +1 @@ +UserKnownHostsFile _known_hosts/localhost_hosts diff --git a/test/fixtures/_known_hosts_real/localhost_hosts b/test/fixtures/_known_hosts/localhost_hosts similarity index 100% rename from test/fixtures/_known_hosts_real/localhost_hosts rename to test/fixtures/_known_hosts/localhost_hosts diff --git a/test/fixtures/_known_hosts/spaced conf b/test/fixtures/_known_hosts/spaced conf new file mode 100644 index 00000000000..ac0891e44df --- /dev/null +++ b/test/fixtures/_known_hosts/spaced conf @@ -0,0 +1,8 @@ + + # Unindented +Host gee + UserKnownHostsFile "_known_hosts/spaced known_hosts" + + # Indented + Host hus #not-a-comment + UserKnownHostsFile "_known_hosts/known_hosts2" diff --git a/test/fixtures/_known_hosts_real/spaced known_hosts b/test/fixtures/_known_hosts/spaced known_hosts similarity index 100% rename from test/fixtures/_known_hosts_real/spaced known_hosts rename to test/fixtures/_known_hosts/spaced known_hosts diff --git a/test/fixtures/_known_hosts_real/config_tilde b/test/fixtures/_known_hosts_real/config_tilde deleted file mode 100644 index 7e710980e40..00000000000 --- a/test/fixtures/_known_hosts_real/config_tilde +++ /dev/null @@ -1,4 +0,0 @@ -# With quotes and tilde, and = -UserKnownHostsFile = "~/_known_hosts_real/known_hosts2" -# Without quotes, with tilde, and another on the same line -UserKnownHostsFile ~/_known_hosts_real/known_hosts3 _known_hosts_real/known_hosts4 diff --git a/test/fixtures/_known_hosts_real/localhost_config b/test/fixtures/_known_hosts_real/localhost_config deleted file mode 100644 index 30b6623bf43..00000000000 --- a/test/fixtures/_known_hosts_real/localhost_config +++ /dev/null @@ -1 +0,0 @@ -UserKnownHostsFile _known_hosts_real/localhost_hosts diff --git a/test/fixtures/_known_hosts_real/spaced conf b/test/fixtures/_known_hosts_real/spaced conf deleted file mode 100644 index 566b92c2184..00000000000 --- a/test/fixtures/_known_hosts_real/spaced conf +++ /dev/null @@ -1,8 +0,0 @@ - - # Unindented -Host gee - UserKnownHostsFile "_known_hosts_real/spaced known_hosts" - - # Indented - Host hus #not-a-comment - UserKnownHostsFile "_known_hosts_real/known_hosts2" diff --git a/test/t/conftest.py b/test/t/conftest.py index 93c8d6cb388..80b2ab80b5f 100644 --- a/test/t/conftest.py +++ b/test/t/conftest.py @@ -132,7 +132,7 @@ def _avahi_hosts(bash: pexpect.spawn) -> List[str]: def known_hosts(bash: pexpect.spawn) -> List[str]: output = assert_bash_exec( bash, - '_known_hosts_real ""; ' + '_comp_compgen_known_hosts ""; ' r'printf "%s\n" "${COMPREPLY[@]}"; unset -v COMPREPLY', want_output=True, ) diff --git a/test/t/unit/Makefile.am b/test/t/unit/Makefile.am index 47f6e56a416..54722dea934 100644 --- a/test/t/unit/Makefile.am +++ b/test/t/unit/Makefile.am @@ -17,7 +17,7 @@ EXTRA_DIST = \ test_unit_get_words.py \ test_unit_initialize.py \ test_unit_ip_addresses.py \ - test_unit_known_hosts_real.py \ + test_unit_known_hosts.py \ test_unit_longopt.py \ test_unit_looks_like_path.py \ test_unit_parse_help.py \ diff --git a/test/t/unit/test_unit_known_hosts_real.py b/test/t/unit/test_unit_known_hosts.py similarity index 78% rename from test/t/unit/test_unit_known_hosts_real.py rename to test/t/unit/test_unit_known_hosts.py index 90a9a4f3ae2..b0f715b3679 100644 --- a/test/t/unit/test_unit_known_hosts_real.py +++ b/test/t/unit/test_unit_known_hosts.py @@ -9,7 +9,7 @@ cmd=None, ignore_env="^[+-](COMPREPLY|BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE)=", ) -class TestUnitKnownHostsReal: +class TestUnitCompgenKnownHosts: @pytest.mark.parametrize( "prefix,colon_flag,hostfile", [("", "", True), ("", "", False), ("user@", "c", True)], @@ -21,9 +21,9 @@ def test_basic( "%s%s%s" % (prefix, x, ":" if colon_flag else "") for x in chain( hosts if hostfile else avahi_hosts, - # fixtures/_known_hosts_real/config + # fixtures/_known_hosts/config "gee hus jar #not-a-comment".split(), - # fixtures/_known_hosts_real/known_hosts + # fixtures/_known_hosts/known_hosts ( "doo", "ike", @@ -49,7 +49,7 @@ def test_basic( ) output = assert_bash_exec( bash, - "_known_hosts_real -a%sF _known_hosts_real/config '%s'; " + "_comp_compgen_known_hosts -a%sF _known_hosts/config '%s'; " r'printf "%%s\n" "${COMPREPLY[@]}"; unset -v COMPREPLY' % (colon_flag, prefix), want_output=True, @@ -72,7 +72,7 @@ def test_ip_filtering(self, bash, family, result): output = assert_bash_exec( bash, "BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE= " - "_known_hosts_real -%sF _known_hosts_real/localhost_config ''; " + "_comp_compgen_known_hosts -%sF _known_hosts/localhost_config ''; " r'printf "%%s\n" "${COMPREPLY[@]}"' % family, want_output=True, ) @@ -80,9 +80,9 @@ def test_ip_filtering(self, bash, family, result): def test_consecutive_spaces(self, bash, hosts): expected = hosts.copy() - # fixtures/_known_hosts_real/spaced conf + # fixtures/_known_hosts/spaced conf expected.extend("gee hus #not-a-comment".split()) - # fixtures/_known_hosts_real/known_hosts2 + # fixtures/_known_hosts/known_hosts2 expected.extend("two two2 two3 two4".split()) # fixtures/_known_hosts_/spaced known_hosts expected.extend("doo ike".split()) @@ -90,7 +90,7 @@ def test_consecutive_spaces(self, bash, hosts): output = assert_bash_exec( bash, "unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE; " - "_known_hosts_real -aF '_known_hosts_real/spaced conf' ''; " + "_comp_compgen_known_hosts -aF '_known_hosts/spaced conf' ''; " r'printf "%s\n" "${COMPREPLY[@]}"', want_output=True, ) @@ -98,11 +98,11 @@ def test_consecutive_spaces(self, bash, hosts): def test_files_starting_with_tilde(self, bash, hosts): expected = hosts.copy() - # fixtures/_known_hosts_real/known_hosts2 + # fixtures/_known_hosts/known_hosts2 expected.extend("two two2 two3 two4".split()) - # fixtures/_known_hosts_real/known_hosts3 + # fixtures/_known_hosts/known_hosts3 expected.append("three") - # fixtures/_known_hosts_real/known_hosts4 + # fixtures/_known_hosts/known_hosts4 expected.append("four") with bash_env_saved(bash) as bash_env: @@ -110,7 +110,7 @@ def test_files_starting_with_tilde(self, bash, hosts): output = assert_bash_exec( bash, "unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;" - " _known_hosts_real -aF _known_hosts_real/config_tilde ''; " + " _comp_compgen_known_hosts -aF _known_hosts/config_tilde ''; " r'printf "%s\n" "${COMPREPLY[@]}"', want_output=True, ) @@ -119,21 +119,21 @@ def test_files_starting_with_tilde(self, bash, hosts): def test_included_configs(self, bash, hosts): expected = hosts.copy() - # fixtures/_known_hosts_real/config_include_recursion + # fixtures/_known_hosts/config_include_recursion expected.append("recursion") - # fixtures/_known_hosts_real/.ssh/config_relative_path + # fixtures/_known_hosts/.ssh/config_relative_path expected.append("relative_path") - # fixtures/_known_hosts_real/.ssh/config_asterisk_* + # fixtures/_known_hosts/.ssh/config_asterisk_* expected.extend("asterisk_1 asterisk_2".split()) - # fixtures/_known_hosts_real/.ssh/config_question_mark + # fixtures/_known_hosts/.ssh/config_question_mark expected.append("question_mark") with bash_env_saved(bash) as bash_env: - bash_env.write_variable("HOME", "%s/_known_hosts_real" % bash.cwd) + bash_env.write_variable("HOME", "%s/_known_hosts" % bash.cwd) output = assert_bash_exec( bash, "unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;" - " _known_hosts_real -aF _known_hosts_real/config_include ''; " + " _comp_compgen_known_hosts -aF _known_hosts/config_include ''; " r'printf "%s\n" "${COMPREPLY[@]}"', want_output=True, ) @@ -141,12 +141,12 @@ def test_included_configs(self, bash, hosts): def test_no_globbing(self, bash): with bash_env_saved(bash) as bash_env: - bash_env.write_variable("HOME", "%s/_known_hosts_real" % bash.cwd) - bash_env.chdir("_known_hosts_real") + bash_env.write_variable("HOME", "%s/_known_hosts" % bash.cwd) + bash_env.chdir("_known_hosts") output = assert_bash_exec( bash, "unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;" - " _known_hosts_real -aF config ''; " + " _comp_compgen_known_hosts -aF config ''; " r'printf "%s\n" "${COMPREPLY[@]}"', want_output=True, ) From 20041eaa9f01f24c779218fba944460bbc9c637d Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 04:20:37 +0900 Subject: [PATCH 08/11] refactor: rename `{ => _comp_compgen}_variables` --- bash_completion | 27 +++++++++++-------- .../000_bash_completion_compat.bash | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/bash_completion b/bash_completion index 432471cdf79..4dfb9ee99e6 100644 --- a/bash_completion +++ b/bash_completion @@ -1136,8 +1136,8 @@ _comp__split_longopt() # Complete variables. # @return True (0) if variables were completed, # False (> 0) if not. -# TODO:API: rename per conventions -_variables() +# @since 2.12 +_comp_compgen_variables() { if [[ $cur =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]]; then # Completing $var / ${var / ${!var / ${#var @@ -1148,10 +1148,10 @@ _variables() if ((${#vars[@]} == 1 && ${#arrs[@]} != 0)); then # Complete ${arr with ${array[ if there is only one match, and that match is an array variable compopt -o nospace - COMPREPLY+=("${arrs[@]}") + _comp_compgen -U vars -U arrs -R -- -W '"${arrs[@]}"' else # Complete ${var with ${variable} - COMPREPLY+=("${vars[@]}") + _comp_compgen -U vars -U arrs -R -- -W '"${vars[@]}"' fi else # Complete $var with $variable @@ -1160,18 +1160,23 @@ _variables() return 0 elif [[ $cur =~ ^(\$\{[#!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]; then # Complete ${array[i with ${array[idx]} - _comp_compgen -ac "${BASH_REMATCH[3]}" -- -W '"${!'"${BASH_REMATCH[2]}"'[@]}"' \ + local vars + _comp_compgen -v vars -c "${BASH_REMATCH[3]}" -- -W '"${!'"${BASH_REMATCH[2]}"'[@]}"' \ -P "${BASH_REMATCH[1]}${BASH_REMATCH[2]}[" -S ']}' # Complete ${arr[@ and ${arr[* if [[ ${BASH_REMATCH[3]} == [@*] ]]; then - COMPREPLY+=("${BASH_REMATCH[1]}${BASH_REMATCH[2]}[${BASH_REMATCH[3]}]}") + vars+=("${BASH_REMATCH[1]}${BASH_REMATCH[2]}[${BASH_REMATCH[3]}]}") + fi + # array indexes may have colons + if ((${#vars[@]})); then + _comp_compgen -U vars -c "$cur" ltrim_colon "${vars[@]}" + else + _comp_compgen_set fi - _comp_ltrim_colon_completions "$cur" # array indexes may have colons return 0 elif [[ $cur =~ ^\$\{[#!]?[A-Za-z0-9_]*\[.*\]$ ]]; then # Complete ${array[idx] with ${array[idx]} - COMPREPLY+=("$cur}") - _comp_ltrim_colon_completions "$cur" + _comp_compgen -c "$cur" ltrim_colon "$cur}" return 0 fi return 1 @@ -1284,7 +1289,7 @@ _comp_variable_assignments() _comp_delimited : -W '$(locale -a 2>/dev/null)' ;; *) - _variables && return 0 + _comp_compgen_variables && return 0 _comp_compgen -a filedir ;; esac @@ -1355,7 +1360,7 @@ _comp_initialize() _comp_get_words -n "$exclude<>&" cur prev words cword # Complete variable names. - _variables && return 1 + _comp_compgen_variables && return 1 # Complete on files if current is a redirect possibly followed by a # filename, e.g. ">foo", or previous is a "bare" redirect, e.g. ">". diff --git a/bash_completion.d/000_bash_completion_compat.bash b/bash_completion.d/000_bash_completion_compat.bash index 0d9730fff4b..d56bbe57904 100644 --- a/bash_completion.d/000_bash_completion_compat.bash +++ b/bash_completion.d/000_bash_completion_compat.bash @@ -13,6 +13,7 @@ _comp_deprecate_func 2.12 _get_comp_words_by_ref _comp_get_words _comp_deprecate_func 2.12 _known_hosts_real _comp_compgen_known_hosts _comp_deprecate_func 2.12 _longopt _comp_longopt _comp_deprecate_func 2.12 __ltrim_colon_completions _comp_ltrim_colon_completions +_comp_deprecate_func 2.12 _variables _comp_compgen_variables _comp_deprecate_func 2.12 _signals _comp_compgen_signals _comp_deprecate_func 2.12 _mac_addresses _comp_compgen_mac_addresses _comp_deprecate_func 2.12 _available_interfaces _comp_compgen_available_interfaces From da26178b9c7eaf11711b451ae292a01bd423a80c Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 10:27:47 +0900 Subject: [PATCH 09/11] fix(_comp_sysvdirs): work around nounset --- bash_completion | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bash_completion b/bash_completion index 4dfb9ee99e6..64d334ec178 100644 --- a/bash_completion +++ b/bash_completion @@ -115,7 +115,7 @@ _comp_sysvdirs() [[ -d /etc/init.d ]] && sysvdirs+=(/etc/init.d) # Slackware uses /etc/rc.d [[ -f /etc/slackware-version ]] && sysvdirs=(/etc/rc.d) - return 0 + ((${#sysvdirs[@]})) } # This function checks whether we have a given program on the system. @@ -1931,7 +1931,7 @@ _comp_compgen_xinetd_services() _comp_compgen_services() { local sysvdirs - _comp_sysvdirs + _comp_sysvdirs || return 1 local services _comp_expand_glob services '${sysvdirs[0]}/!($_comp_backup_glob|functions|README)' @@ -1972,7 +1972,7 @@ _service() [[ -e /etc/mandrake-release ]] && _comp_compgen_xinetd_services else local sysvdirs - _comp_sysvdirs + _comp_sysvdirs || return 1 _comp_compgen_split -l -- "$(command sed -e 'y/|/ /' \ -ne 's/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p' \ "${sysvdirs[0]}/${prev##*/}" 2>/dev/null) start stop" @@ -1983,12 +1983,12 @@ _service() _comp__init_set_up_service_completions() { local sysvdirs svc svcdir - _comp_sysvdirs - for svcdir in "${sysvdirs[@]}"; do - for svc in "$svcdir"/!($_comp_backup_glob); do - [[ -x $svc ]] && complete -F _service "$svc" + _comp_sysvdirs && + for svcdir in "${sysvdirs[@]}"; do + for svc in "$svcdir"/!($_comp_backup_glob); do + [[ -x $svc ]] && complete -F _service "$svc" + done done - done unset -f "$FUNCNAME" } _comp__init_set_up_service_completions From 43bb8f03798811d95a3068a8a53d2eac9ad877b5 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 11:55:00 +0900 Subject: [PATCH 10/11] feat(_comp_compgen_known_hosts): return 2 on usage error --- bash_completion | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bash_completion b/bash_completion index 64d334ec178..7380d7ebdd9 100644 --- a/bash_completion +++ b/bash_completion @@ -2476,7 +2476,7 @@ _comp_compgen_known_hosts__impl() F) if [[ ! $OPTARG ]]; then echo "bash_completion: $FUNCNAME: -F: an empty filename is specified" >&2 - return 1 + return 2 fi configfile=$OPTARG ;; @@ -2485,13 +2485,13 @@ _comp_compgen_known_hosts__impl() 6) ipv6=set ;; *) echo "bash_completion: $FUNCNAME: usage error" >&2 - return 1 + return 2 ;; esac done if (($# < OPTIND)); then echo "bash_completion: $FUNCNAME: missing mandatory argument CWORD" >&2 - return 1 + return 2 fi cur=${!OPTIND} ((OPTIND += 1)) @@ -2501,7 +2501,7 @@ _comp_compgen_known_hosts__impl() printf '%s ' ${!OPTIND} shift done)" >&2 - return 1 + return 2 fi [[ $cur == *@* ]] && prefix=$prefix${cur%@*}@ && cur=${cur#*@} From d2860cb481be8f3cf97172cb1bf063da8f238e53 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 13 Aug 2023 11:56:21 +0900 Subject: [PATCH 11/11] fix(_comp_compgen_known_hosts): work around bash-4.2 nounset --- bash_completion | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/bash_completion b/bash_completion index 7380d7ebdd9..1459d6ff141 100644 --- a/bash_completion +++ b/bash_completion @@ -2642,21 +2642,22 @@ _comp_compgen_known_hosts__impl() _comp_compgen -av known_hosts -- -A hostname -P "$prefix" -S "$suffix" fi - if ((${#known_hosts[@]})); then - if [[ $ipv4 ]]; then - known_hosts=("${known_hosts[@]/*:*$suffix/}") - fi - if [[ $ipv6 ]]; then - known_hosts=("${known_hosts[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}") - fi - if [[ $ipv4 || $ipv6 ]]; then - for i in "${!known_hosts[@]}"; do - [[ ${known_hosts[i]} ]] || unset -v 'known_hosts[i]' - done - fi - _comp_compgen -v known_hosts -c "$prefix$cur" ltrim_colon "${known_hosts[@]}" + ((${#known_hosts[@]})) || return 1 + + if [[ $ipv4 ]]; then + known_hosts=("${known_hosts[@]/*:*$suffix/}") + fi + if [[ $ipv6 ]]; then + known_hosts=("${known_hosts[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}") + fi + if [[ $ipv4 || $ipv6 ]]; then + for i in "${!known_hosts[@]}"; do + [[ ${known_hosts[i]} ]] || unset -v 'known_hosts[i]' + done fi + ((${#known_hosts[@]})) || return 1 + _comp_compgen -v known_hosts -c "$prefix$cur" ltrim_colon "${known_hosts[@]}" } # _comp_compgen_known_hosts__impl() complete -F _known_hosts traceroute traceroute6 \ fping fping6 telnet rsh rlogin ftp dig drill mtr ssh-installkeys showmount