@@ -467,6 +467,14 @@ _comp_cmd_scp__path_esc='[][(){}<>"'"'"',:;^&!$=?`\\|[:space:]]'
467467# "compopt +o nospace" instead, but it would suffix a space to directory names
468468# unexpectedly.
469469#
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+ #
470478# Options:
471479# -d Only directory names are selected.
472480# @param $1 escape_replacement - If a non-empty value is specified, special
@@ -530,13 +538,16 @@ _comp_xfunc_scp_compgen_remote_files()
530538 done
531539
532540 # 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-}
537548
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 #*: }
540551
541552 # default to home dir of specified user on remote host
542553 if [[ ! $_path ]]; then
@@ -575,8 +586,12 @@ _comp_xfunc_scp_compgen_local_files()
575586 shift
576587 fi
577588
589+ local REPLY
590+ _comp_dequote " $cur " || REPLY=$cur
591+ local cur_val=${REPLY-}
592+
578593 local files
579- _comp_expand_glob files ' "$cur "*' || return 0
594+ _comp_expand_glob files ' "$cur_val "*' || return 0
580595 _comp_compgen -RU files split -l ${1: +-P " $1 " } -- " $(
581596 command ls -aF1dL " ${files[@]} " 2> /dev/null |
582597 _comp_cmd_scp__escape_path ${_dirs_only: +' -d' }
0 commit comments