Skip to content

fix(scp,rsync): fix misc bugs and refactor #1371

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 10 additions & 14 deletions completions/ssh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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' \
Expand All @@ -539,26 +535,26 @@ _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
_comp_compgen -RU files split -l -- "$(
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" \
-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
}
Expand Down Expand Up @@ -588,7 +584,7 @@ _comp_cmd_scp()
return
}

local ipvx
local ipvx=

case $prev in
-*c)
Expand Down Expand Up @@ -640,7 +636,7 @@ _comp_cmd_scp()
;;
esac

local prefix
local prefix=

if [[ $cur == -F* ]]; then
cur=${cur#-F}
Expand Down
2 changes: 1 addition & 1 deletion test/t/test_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion test/t/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) :]
Expand Down
2 changes: 1 addition & 1 deletion test/t/test_man.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down