Skip to content

Commit 040b117

Browse files
authored
Merge pull request #1397 from akinomyoga/scp-refactor-1-2
fix(rsync,ssh,sshfs): do not generate regular files *'\' as dirs
2 parents 98207f4 + 2c54a45 commit 040b117

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

completions/ssh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,15 @@ _comp_xfunc_scp_compgen_remote_files()
512512
# shellcheck disable=SC2090
513513
_files=$(ssh -o 'Batchmode yes' "$_userhost" \
514514
command ls -aF1dL "$_path*" 2>/dev/null |
515-
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e '/[^\/]$/d')
515+
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e '/[^/]$/d')
516516
else
517517
# escape problematic characters; remove executables, aliases, pipes
518518
# and sockets; add space at end of file names
519519
# shellcheck disable=SC2090
520520
_files=$(ssh -o 'Batchmode yes' "$_userhost" \
521521
command ls -aF1dL "$_path*" 2>/dev/null |
522522
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e 's/[*@|=]$//g' \
523-
-e 's/[^\/]$/& /g')
523+
-e 's/[^/]$/& /g')
524524
fi
525525
_comp_compgen -R split -l -- "$_files"
526526
}
@@ -550,13 +550,13 @@ _comp_xfunc_scp_compgen_local_files()
550550
_comp_compgen -RU files split -l -- "$(
551551
command ls -aF1dL "${files[@]}" 2>/dev/null |
552552
command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
553-
-e '/[^\/]$/d' -e "s/^/${1-}/"
553+
-e '/[^/]$/d' -e "s/^/${1-}/"
554554
)"
555555
else
556556
_comp_compgen -RU files split -l -- "$(
557557
command ls -aF1dL "${files[@]}" 2>/dev/null |
558558
command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
559-
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' -e "s/^/${1-}/"
559+
-e 's/[*@|=]$//g' -e 's/[^/]$/& /g' -e "s/^/${1-}/"
560560
)"
561561
fi
562562
}

completions/sshfs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ _comp_cmd_sshfs()
88
_comp_expand || return
99

1010
if [[ $cur == *:* ]]; then
11-
_comp_compgen -x scp remote_files -d
12-
# unlike scp and rsync, sshfs works with 1 backslash instead of 3
13-
COMPREPLY=("${COMPREPLY[@]//\\\\\\/\\}")
11+
if _comp_compgen -x scp remote_files -d; then
12+
# unlike scp and rsync, sshfs works with 1 backslash instead of 3
13+
COMPREPLY=("${COMPREPLY[@]//\\\\\\/\\}")
14+
fi
1415
return
1516
fi
1617

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

Whitespace-only changes.

test/fixtures/sshfs/local_path-file\

Whitespace-only changes.

test/t/test_sshfs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import pytest
22

3+
from conftest import assert_bash_exec, assert_complete
4+
35

46
@pytest.mark.bashcomp(ignore_env=r"^[+-]_comp_cmd_scp__path_esc=")
57
class TestSshfs:
68
@pytest.mark.complete("sshfs ./")
79
def test_1(self, completion):
810
assert completion
11+
12+
@pytest.mark.complete("sshfs local_path", cwd="sshfs")
13+
def test_local_path_suffix_1(self, completion):
14+
assert completion == "-dir/"
15+
16+
def test_remote_path_ending_with_backslash(self, bash):
17+
assert_bash_exec(bash, "ssh() { echo 'hypothetical\\'; }")
18+
completion = assert_complete(bash, "sshfs remote_host:hypo")
19+
assert_bash_exec(bash, "unset -f ssh")
20+
assert not completion

0 commit comments

Comments
 (0)