File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -540,7 +540,21 @@ _comp_xfunc_scp_compgen_remote_files()
540
540
local REPLY=$cur
541
541
if [[ ! $_less_escaping ]]; then
542
542
# unescape (3 backslashes to 1 for chars we escaped)
543
- REPLY=$( command sed -e ' s/\\\\\\\(' " $_comp_cmd_scp__path_esc " ' \)/\\\1/g' <<< " $REPLY" )
543
+ #
544
+ # Note: We want to do the following, but POSIX BRE does not support \|:
545
+ #
546
+ # REPLY=$(command sed -e 's/\\\\\\\('"$_comp_cmd_scp__path_esc"'\|$\)/\\\1/g' <<<"$REPLY")
547
+ #
548
+ # Note: We need to store \\\\\\ in a variable to work around "shopt -s
549
+ # compat31".
550
+ local _tail=$REPLY _regex_triple_backslashes=' \\\\\\(' $_comp_cmd_scp__path_esc ' |$)(.*)$'
551
+ REPLY=
552
+ while [[ $_tail && $_tail =~ $_regex_triple_backslashes ]]; do
553
+ # shellcheck disable=SC1003
554
+ REPLY=${_tail:: ${# _tail} -${# BASH_REMATCH} } ' \' ${BASH_REMATCH[1]}
555
+ _tail=${BASH_REMATCH[2]}
556
+ done
557
+ REPLY+=$_tail
544
558
fi
545
559
_comp_dequote_incomplete " $REPLY "
546
560
local cur_val=${REPLY-}
Original file line number Diff line number Diff line change @@ -144,6 +144,15 @@ def test_remote_path_with_backslash(self, bash):
144
144
[r"abc\ def.txt" , r"abc\\\ def.txt" ]
145
145
) or completion == sorted ([r"abc\\\ def.txt" , r"abc\\\\\\\ def.txt" ])
146
146
147
+ def test_remote_path_with_backslash_2 (self , bash ):
148
+ assert_bash_exec (
149
+ bash , r"ssh() { [[ $1 == abc ]]; printf '%s\n' 'abc OK'; }"
150
+ )
151
+ completion = assert_complete (bash , "scp remote_host:abc\\ \\ \\ " )
152
+ assert_bash_exec (bash , "unset -f ssh" )
153
+
154
+ assert completion == "OK"
155
+
147
156
def test_xfunc_remote_files (self , bash ):
148
157
with bash_env_saved (bash ) as bash_env :
149
158
bash_env .save_variable ("COMPREPLY" )
You can’t perform that action at this time.
0 commit comments