@@ -467,6 +467,14 @@ _comp_cmd_scp__path_esc='[][(){}<>"'"'"',:;^&!$=?`\\|[:space:]]'
467
467
# "compopt +o nospace" instead, but it would suffix a space to directory names
468
468
# unexpectedly.
469
469
#
470
+ # FIXME: With the current strategy of using "ls -FL", we cannot distinguish the
471
+ # filenames that end with one of the type-classifier characters. For example,
472
+ # a regular file "pipe|" and a named pipe "pipe" would both produce the
473
+ # identical result "pipe|" with "ls -1FL". As a consequence, those characters
474
+ # at the end of the filename are removed unexpectedly. To solve this problem,
475
+ # we need to give up relying on "ls -1FL". See
476
+ # https://github.com/scop/bash-completion/issues/1245
477
+ #
470
478
# Options:
471
479
# -d Only directory names are selected.
472
480
# @param $1 escape_replacement - If a non-empty value is specified, special
@@ -530,13 +538,16 @@ _comp_xfunc_scp_compgen_remote_files()
530
538
done
531
539
532
540
# remove backslash escape from the first colon
533
- local cur=${cur/ \\ :/: }
534
-
535
- local _userhost=${cur%% ?(\\ ):* }
536
- local _path=${cur#*: }
541
+ local REPLY=$cur
542
+ if [[ ! $_less_escaping ]]; then
543
+ # unescape (3 backslashes to 1 for chars we escaped)
544
+ REPLY=$( command sed -e ' s/\\\\\\\(' " $_comp_cmd_scp__path_esc " ' \)/\\\1/g' <<< " $REPLY" )
545
+ fi
546
+ _comp_dequote " $REPLY "
547
+ local cur_val=${REPLY-}
537
548
538
- # unescape (3 backslashes to 1 for chars we escaped)
539
- _path=$( command sed -e ' s/\\\\\\\( ' " $_comp_cmd_scp__path_esc " ' \)/\\\1/g ' <<< " $_path " )
549
+ local _userhost= ${cur_val %%:* }
550
+ local _path=${cur_val #*: }
540
551
541
552
# default to home dir of specified user on remote host
542
553
if [[ ! $_path ]]; then
@@ -575,8 +586,12 @@ _comp_xfunc_scp_compgen_local_files()
575
586
shift
576
587
fi
577
588
589
+ local REPLY
590
+ _comp_dequote " $cur " || REPLY=$cur
591
+ local cur_val=${REPLY-}
592
+
578
593
local files
579
- _comp_expand_glob files ' "$cur "*' || return 0
594
+ _comp_expand_glob files ' "$cur_val "*' || return 0
580
595
_comp_compgen -RU files split -l ${1: +-P " $1 " } -- " $(
581
596
command ls -aF1dL " ${files[@]} " 2> /dev/null |
582
597
_comp_cmd_scp__escape_path ${_dirs_only: +' -d' }
0 commit comments