Skip to content

Commit 07ac056

Browse files
committed
[waiting for PR1371]
* fix(scp): fix a bug that `-F<prefix>[TAB]` did not complete at all * fix(rsync,ssh,sshfs): do not generate regular files *'\' as dirs * fix(rsync,scp): remove file-type marks from "ls -F" properly * refactor(ssh): remove outdated disable=SC2089,SC2090 * refactor(scp): use "_comp_compgen_split -P" to add prefix * fix(_comp_command_offset): work around nounset * refactor(scp): rename local var "_dirs{ => _}only" for consistency * test(cancel,ls,man): remove redundant "return"
1 parent 90162b0 commit 07ac056

File tree

9 files changed

+54
-20
lines changed

9 files changed

+54
-20
lines changed

bash_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2856,7 +2856,7 @@ _comp_command_offset()
28562856
_comp_compgen_commands
28572857
else
28582858
_comp_dequote "${COMP_WORDS[0]}" || REPLY=${COMP_WORDS[0]}
2859-
local cmd=$REPLY compcmd=$REPLY
2859+
local cmd=${REPLY-} compcmd=${REPLY-}
28602860
local cspec=$(complete -p -- "$cmd" 2>/dev/null)
28612861

28622862
# If we have no completion for $cmd yet, see if we have for basename

completions/ssh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ _comp_cmd_sftp()
459459
shopt -u hostcomplete && complete -F _comp_cmd_sftp sftp
460460

461461
# things we want to backslash escape in scp paths
462-
# shellcheck disable=SC2089
463462
_comp_cmd_scp__path_esc='[][(){}<>"'"'"',:;^&!$=?`\\|[:space:]]'
464463

465464
# Complete remote files with ssh. Returns paths escaped with three backslashes
@@ -493,7 +492,6 @@ _comp_xfunc_scp_compgen_remote_files()
493492
local _path=${cur#*:}
494493

495494
# unescape (3 backslashes to 1 for chars we escaped)
496-
# shellcheck disable=SC2090
497495
_path=$(command sed -e 's/\\\\\\\('"$_comp_cmd_scp__path_esc"'\)/\\\1/g' <<<"$_path")
498496

499497
# default to home dir of specified user on remote host
@@ -509,18 +507,17 @@ _comp_xfunc_scp_compgen_remote_files()
509507
local _files
510508
if [[ $_dirs_only ]]; then
511509
# escape problematic characters; remove non-dirs
512-
# shellcheck disable=SC2090
513510
_files=$(ssh -o 'Batchmode yes' "$_userhost" \
514511
command ls -aF1dL "$_path*" 2>/dev/null |
515-
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e '/[^\/]$/d')
512+
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e '/[^/]$/d')
516513
else
517514
# escape problematic characters; remove executables, aliases, pipes
518515
# and sockets; add space at end of file names
519-
# shellcheck disable=SC2090
520516
_files=$(ssh -o 'Batchmode yes' "$_userhost" \
521517
command ls -aF1dL "$_path*" 2>/dev/null |
522-
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e 's/[*@|=]$//g' \
523-
-e 's/[^\/]$/& /g')
518+
command sed -e 's/[*@|=]$//g' \
519+
-e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' \
520+
-e 's/[^/]$/& /g')
524521
fi
525522
_comp_compgen -R split -l -- "$_files"
526523
}
@@ -538,25 +535,26 @@ _scp_remote_files()
538535
# @since 2.12
539536
_comp_xfunc_scp_compgen_local_files()
540537
{
541-
local _dirsonly=""
538+
local _dirs_only=""
542539
if [[ ${1-} == -d ]]; then
543-
_dirsonly=set
540+
_dirs_only=set
544541
shift
545542
fi
546543

547544
local files
548545
_comp_expand_glob files '"$cur"*' || return 0
549-
if [[ $_dirsonly ]]; then
550-
_comp_compgen -U files split -l -- "$(
546+
if [[ $_dirs_only ]]; then
547+
_comp_compgen -RU files split -l ${1:+-P "$1"} -- "$(
551548
command ls -aF1dL "${files[@]}" 2>/dev/null |
552549
command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
553-
-e '/[^\/]$/d' -e "s/^/${1-}/"
550+
-e '/[^/]$/d'
554551
)"
555552
else
556-
_comp_compgen -U files split -l -- "$(
553+
_comp_compgen -RU files split -l ${1:+-P "$1"} -- "$(
557554
command ls -aF1dL "${files[@]}" 2>/dev/null |
558-
command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
559-
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' -e "s/^/${1-}/"
555+
command sed -e 's/[*@|=]$//g' \
556+
-e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
557+
-e 's/[^/]$/& /g'
560558
)"
561559
fi
562560
}

test/fixtures/sshfs/local_path-dir/dummy.txt

Whitespace-only changes.

test/fixtures/sshfs/local_path-file\

Whitespace-only changes.

test/t/test_cancel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def added_job(self, request, bash):
1616
)
1717
except AssertionError:
1818
pytest.skip("Could not add test print job")
19-
return
19+
2020
if len(got) > 3:
2121
request.addfinalizer(
2222
lambda: assert_bash_exec(bash, "cancel %s" % got[3])

test/t/test_ls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_3(self, bash):
3333
part_full = find_unique_completion_pair(res)
3434
if not part_full:
3535
pytest.skip("No suitable test user found")
36-
return
36+
3737
part, full = part_full
3838
completion = assert_complete(bash, "ls ~%s" % part)
3939
assert completion == full[len(part) :]

test/t/test_man.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def colonpath(self, request, bash):
2323
pass
2424
else:
2525
pytest.skip("Cygwin doesn't like paths with colons")
26-
return
26+
2727
tmpdir, _, _ = prepare_fixture_dir(
2828
request,
2929
files=["man/man3/Bash::Completion.3pm.gz"],

test/t/test_scp.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import pytest
44

5-
from conftest import assert_bash_exec, assert_complete, bash_env_saved
5+
from conftest import (
6+
assert_bash_exec,
7+
assert_complete,
8+
bash_env_saved,
9+
prepare_fixture_dir,
10+
)
611

712
LIVE_HOST = "bash_completion"
813

@@ -55,6 +60,14 @@ def test_capital_f_without_space(self, completion):
5560
"option requires an argument -- F" in x for x in completion
5661
)
5762

63+
@pytest.mark.complete("scp -Fconf", cwd="scp")
64+
def test_capital_f_without_space_2(self, completion):
65+
assert completion == "ig"
66+
67+
@pytest.mark.complete("scp -Fbi", cwd="scp")
68+
def test_capital_f_without_space_3(self, completion):
69+
assert completion == "n/"
70+
5871
@pytest.fixture(scope="class")
5972
def live_pwd(self, bash):
6073
try:
@@ -141,3 +154,22 @@ def test_xfunc_remote_files(self, bash):
141154
"shared/default/foo ",
142155
"shared/default/foo.d/",
143156
]
157+
158+
@pytest.fixture
159+
def tmpdir_mkfifo(self, request, bash):
160+
tmpdir, _, _ = prepare_fixture_dir(request, files=[], dirs=[])
161+
162+
try:
163+
assert_bash_exec(bash, "mkfifo '%s/local_path_1-pipe'" % tmpdir)
164+
except Exception:
165+
pytest.skip(
166+
"The present system does not allow creating a named pipe."
167+
)
168+
169+
return tmpdir
170+
171+
def test_local_path_mark_1(self, bash, tmpdir_mkfifo):
172+
completion = assert_complete(
173+
bash, "scp local_path_1-", cwd=tmpdir_mkfifo
174+
)
175+
assert completion == "pipe"

test/t/test_sshfs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ class TestSshfs:
66
@pytest.mark.complete("sshfs ./")
77
def test_1(self, completion):
88
assert completion
9+
10+
@pytest.mark.complete("sshfs local_path", cwd="sshfs")
11+
def test_local_path_suffix_1(self, completion):
12+
assert completion == "-dir/"

0 commit comments

Comments
 (0)