@@ -434,8 +434,11 @@ _comp_cmd_scp__path_esc='[][(){}<>"'"'"',:;^&!$=?`\\|[:space:]]'
434
434
# Complete remote files with ssh. If the first arg is -d, complete on dirs
435
435
# only. Returns paths escaped with three backslashes.
436
436
# shellcheck disable=SC2120
437
+ # @param $1 `no-overescape` if we should use 1 backslash for escaping instead of 3
437
438
_comp_xfunc_ssh_scp_remote_files ()
438
439
{
440
+ local no_overescape=$1
441
+
439
442
# remove backslash escape from the first colon
440
443
cur=${cur/ \\ :/: }
441
444
@@ -451,20 +454,25 @@ _comp_xfunc_ssh_scp_remote_files()
451
454
path=$( ssh -o ' Batchmode yes' " $userhost " pwd 2> /dev/null)
452
455
fi
453
456
457
+ local escape_replacement=' \\\\\\&'
458
+ if [[ " $no_overescape " == " no-overescape" ]]; then
459
+ escape_replacement=' \\&'
460
+ fi
461
+
454
462
local files
455
463
if [[ ${1-} == -d ]]; then
456
464
# escape problematic characters; remove non-dirs
457
465
# shellcheck disable=SC2090
458
466
files=$( ssh -o ' Batchmode yes' " $userhost " \
459
467
command ls -aF1dL " $path *" 2> /dev/null |
460
- command sed -e ' s/' " $_comp_cmd_scp__path_esc " ' /\\& /g' -e ' /[^\/]$/d' )
468
+ command sed -e ' s/' " $_comp_cmd_scp__path_esc " ' /' " $escape_replacement " ' /g' -e ' /[^\/]$/d' )
461
469
else
462
470
# escape problematic characters; remove executables, aliases, pipes
463
471
# and sockets; add space at end of file names
464
472
# shellcheck disable=SC2090
465
473
files=$( ssh -o ' Batchmode yes' " $userhost " \
466
474
command ls -aF1dL " $path *" 2> /dev/null |
467
- command sed -e ' s/' " $_comp_cmd_scp__path_esc " ' /\\& /g' -e ' s/[*@|=]$//g' \
475
+ command sed -e ' s/' " $_comp_cmd_scp__path_esc " ' /' " $escape_replacement " ' /g' -e ' s/[*@|=]$//g' \
468
476
-e ' s/[^\/]$/& /g' )
469
477
fi
470
478
_comp_split -la COMPREPLY " $files "
0 commit comments