Skip to content

Commit 8ca4fa9

Browse files
committed
refactor(ssh): accept dironly flag as an option
1 parent a81b879 commit 8ca4fa9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

completions/ssh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,19 @@ _comp_cmd_scp__path_esc='[][(){}<>"'"'"',:;^&!$=?`\\|[:space:]]'
488488
# types of the files.
489489
_comp_cmd_scp__escape_path()
490490
{
491-
local dirs_only=$1 escape_replacement=${2:-'\\&'}
491+
local OPTIND=1 OPTARG="" OPTERR=0 opt dirs_only=""
492+
while getopts ':d' _flag "$@"; do
493+
case $_flag in
494+
d) dirs_only=set ;;
495+
*)
496+
echo "bash_completion: $FUNCNAME: usage error: $*" >&2
497+
return 1
498+
;;
499+
esac
500+
done
501+
shift "$((OPTIND - 1))"
502+
local escape_replacement=${1:-'\\&'}
503+
492504
if [[ $dirs_only ]]; then
493505
# escape problematic characters; remove non-dirs
494506
command sed \
@@ -553,7 +565,8 @@ _comp_xfunc_scp_compgen_remote_files()
553565
local _files
554566
_files=$(ssh -o 'Batchmode yes' "$_userhost" \
555567
command ls -aF1dL "$_path*" 2>/dev/null |
556-
_comp_cmd_scp__escape_path "$_dirs_only" "$_escape_replacement")
568+
_comp_cmd_scp__escape_path ${_dirs_only:+'-d'} -- \
569+
"$_escape_replacement")
557570
_comp_compgen -R split -l -- "$_files"
558571
}
559572

@@ -584,7 +597,7 @@ _comp_xfunc_scp_compgen_local_files()
584597
_comp_expand_glob files '"$cur_val"*' || return 0
585598
_comp_compgen -RU files split -l ${1:+-P "$1"} -- "$(
586599
command ls -aF1dL "${files[@]}" 2>/dev/null |
587-
_comp_cmd_scp__escape_path "$_dirsonly"
600+
_comp_cmd_scp__escape_path ${_dirsonly:+'-d'}
588601
)"
589602
}
590603

0 commit comments

Comments
 (0)