Skip to content

Commit 58ed923

Browse files
committed
scp: avoid double expansion of file
- Use `_comp_xfunc_ssh_scp_local_files` only for `-F` option. - Otherwise use `_filedir` and add heuristics based on number of completion variants whether the argument is hostname or it is a local file, so a space should be appended.
1 parent b85b88e commit 58ed923

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

completions/ssh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,10 @@ _scp()
565565
;;
566566
esac
567567

568-
local prefix
569-
570568
if [[ $cur == -F* ]]; then
571569
cur=${cur#-F}
572-
prefix=-F
570+
# _filedir will not add -F prefix
571+
_comp_xfunc_ssh_scp_local_files -F
573572
else
574573
case $cur in
575574
-*)
@@ -579,17 +578,22 @@ _scp()
579578
return
580579
;;
581580
*/* | [.~]*)
582-
# not a known host
583-
_filedir
581+
# not a known host, pass through
584582
;;
585583
*)
586584
_known_hosts_real ${ipvx-} -c -a \
587585
${configfile:+-F "$configfile"} -- "$cur"
588586
;;
589587
esac
588+
local count=${#COMPREPLY[@]}
589+
# Keep "~" prefix.
590+
_filedir
591+
# Do not append space to known host.
592+
if [ $count -ne ${#COMPREPLY[@]} ]; then
593+
compopt +o nospace
594+
fi
590595
fi
591596

592-
_comp_xfunc_ssh_scp_local_files "${prefix-}"
593597
} &&
594598
complete -F _scp -o nospace scp
595599

0 commit comments

Comments
 (0)