From 42eeeca20aaa806afc461eab461416a748c83271 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 5 Apr 2025 15:37:56 +0900 Subject: [PATCH 1/6] refactor(ssh): remove outdated disable=SC2089,SC2090 These shellcheck directives were added in commit c906aeb (2020-04-10), but the latest version of shellcheck-0.10.0 does not seem to warn about SC2089 and SC2090 on these lines for the current version of bash_completion. These warnings seem to be issued when unquoted $_comp_cmd_scp__path_esc is used, such as echo $_comp_cmd_scp__path_esc We have already resolved those unquoted variable expansions, so the warning should no longer happen. In this patch, we remove those outdated shellcheck directives. --- completions/ssh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/completions/ssh b/completions/ssh index 279c44b040a..8df5f3c96f0 100644 --- a/completions/ssh +++ b/completions/ssh @@ -459,7 +459,6 @@ _comp_cmd_sftp() shopt -u hostcomplete && complete -F _comp_cmd_sftp sftp # things we want to backslash escape in scp paths -# shellcheck disable=SC2089 _comp_cmd_scp__path_esc='[][(){}<>"'"'"',:;^&!$=?`\\|[:space:]]' # Complete remote files with ssh. Returns paths escaped with three backslashes @@ -493,7 +492,6 @@ _comp_xfunc_scp_compgen_remote_files() local _path=${cur#*:} # unescape (3 backslashes to 1 for chars we escaped) - # shellcheck disable=SC2090 _path=$(command sed -e 's/\\\\\\\('"$_comp_cmd_scp__path_esc"'\)/\\\1/g' <<<"$_path") # default to home dir of specified user on remote host @@ -509,14 +507,12 @@ _comp_xfunc_scp_compgen_remote_files() local _files if [[ $_dirs_only ]]; then # escape problematic characters; remove non-dirs - # shellcheck disable=SC2090 _files=$(ssh -o 'Batchmode yes' "$_userhost" \ command ls -aF1dL "$_path*" 2>/dev/null | command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e '/[^/]$/d') else # escape problematic characters; remove executables, aliases, pipes # and sockets; add space at end of file names - # shellcheck disable=SC2090 _files=$(ssh -o 'Batchmode yes' "$_userhost" \ command ls -aF1dL "$_path*" 2>/dev/null | command sed -e 's/[*@|=]$//g' \ From 095748e33ad339f7aa1302706056e1bab25e6143 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 5 Apr 2025 13:31:43 +0900 Subject: [PATCH 2/6] refactor(scp): use "_comp_compgen_split -P" to add prefix --- completions/ssh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/completions/ssh b/completions/ssh index 8df5f3c96f0..236e16a3775 100644 --- a/completions/ssh +++ b/completions/ssh @@ -544,17 +544,17 @@ _comp_xfunc_scp_compgen_local_files() local files _comp_expand_glob files '"$cur"*' || return 0 if [[ $_dirsonly ]]; then - _comp_compgen -RU files split -l -- "$( + _comp_compgen -RU files split -l ${1:+-P "$1"} -- "$( command ls -aF1dL "${files[@]}" 2>/dev/null | command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \ - -e '/[^/]$/d' -e "s/^/${1-}/" + -e '/[^/]$/d' )" else - _comp_compgen -RU files split -l -- "$( + _comp_compgen -RU files split -l ${1:+-P "$1"} -- "$( command ls -aF1dL "${files[@]}" 2>/dev/null | command sed -e 's/[*@|=]$//g' \ -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \ - -e 's/[^/]$/& /g' -e "s/^/${1-}/" + -e 's/[^/]$/& /g' )" fi } From 28e19a2bdcc0ce2150bd807e809463e2124d01b9 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 5 Apr 2025 22:21:13 +0900 Subject: [PATCH 3/6] fix(_comp_command_offset): work around nounset --- bash_completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_completion b/bash_completion index 4e488d44564..ecaecd3511c 100644 --- a/bash_completion +++ b/bash_completion @@ -2860,7 +2860,7 @@ _comp_command_offset() _comp_compgen_commands else _comp_dequote "${COMP_WORDS[0]}" || REPLY=${COMP_WORDS[0]} - local cmd=$REPLY compcmd=$REPLY + local cmd=${REPLY-} compcmd=${REPLY-} local cspec=$(complete -p -- "$cmd" 2>/dev/null) # If we have no completion for $cmd yet, see if we have for basename From a4fee73e36289a12d9e42e7b9877c7a85b0c7130 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 7 Apr 2025 08:15:50 +0900 Subject: [PATCH 4/6] refactor(scp): rename local var "_dirs{ => _}only" for consistency --- completions/ssh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/completions/ssh b/completions/ssh index 236e16a3775..55753333684 100644 --- a/completions/ssh +++ b/completions/ssh @@ -535,15 +535,15 @@ _scp_remote_files() # @since 2.12 _comp_xfunc_scp_compgen_local_files() { - local _dirsonly="" + local _dirs_only="" if [[ ${1-} == -d ]]; then - _dirsonly=set + _dirs_only=set shift fi local files _comp_expand_glob files '"$cur"*' || return 0 - if [[ $_dirsonly ]]; then + if [[ $_dirs_only ]]; then _comp_compgen -RU files split -l ${1:+-P "$1"} -- "$( command ls -aF1dL "${files[@]}" 2>/dev/null | command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \ From e48ef7949ccbaeaa11f8011d40204daa8bc15f1b Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 7 Apr 2025 09:06:15 +0900 Subject: [PATCH 5/6] test(cancel,ls,man): remove redundant "return" pytest.skip cancels the execution of the current test, so "return" and subsequent codes arex unreachable. We do not need to explicitly call "return" in this context. https://github.com/scop/bash-completion/pull/1357#discussion_r2030308800 --- test/t/test_cancel.py | 2 +- test/t/test_ls.py | 2 +- test/t/test_man.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/t/test_cancel.py b/test/t/test_cancel.py index 4aeafd2c5fa..9384908c630 100644 --- a/test/t/test_cancel.py +++ b/test/t/test_cancel.py @@ -16,7 +16,7 @@ def added_job(self, request, bash): ) except AssertionError: pytest.skip("Could not add test print job") - return + if len(got) > 3: request.addfinalizer( lambda: assert_bash_exec(bash, "cancel %s" % got[3]) diff --git a/test/t/test_ls.py b/test/t/test_ls.py index f91ee6b2e2e..56f0ee71e90 100644 --- a/test/t/test_ls.py +++ b/test/t/test_ls.py @@ -33,7 +33,7 @@ def test_3(self, bash): part_full = find_unique_completion_pair(res) if not part_full: pytest.skip("No suitable test user found") - return + part, full = part_full completion = assert_complete(bash, "ls ~%s" % part) assert completion == full[len(part) :] diff --git a/test/t/test_man.py b/test/t/test_man.py index 081b8fcc1e7..bec41de9613 100644 --- a/test/t/test_man.py +++ b/test/t/test_man.py @@ -23,7 +23,7 @@ def colonpath(self, request, bash): pass else: pytest.skip("Cygwin doesn't like paths with colons") - return + tmpdir, _, _ = prepare_fixture_dir( request, files=["man/man3/Bash::Completion.3pm.gz"], From b9680a7d278520b4ee2fa87d965cc559efb1aa68 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 3 Aug 2025 21:49:47 +0900 Subject: [PATCH 6/6] fix(ssh): work around localvar_inherit --- completions/ssh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/completions/ssh b/completions/ssh index 55753333684..d32819e1d13 100644 --- a/completions/ssh +++ b/completions/ssh @@ -302,7 +302,7 @@ _comp_cmd_ssh() _comp_cmd_ssh__compgen_suboption_check "$1" && return - local ipvx + local ipvx= # Keep cases sorted the same they're in ssh's usage message # (but do group ones with same arg completion) @@ -584,7 +584,7 @@ _comp_cmd_scp() return } - local ipvx + local ipvx= case $prev in -*c) @@ -636,7 +636,7 @@ _comp_cmd_scp() ;; esac - local prefix + local prefix= if [[ $cur == -F* ]]; then cur=${cur#-F}