Skip to content

Commit 18e436d

Browse files
scopakinomyoga
andcommitted
fix(ssh-keygen): handling of bundled short options
Co-authored-by: Koichi Murase <[email protected]>
1 parent d6977fc commit 18e436d

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

completions/ssh-keygen

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ _comp_cmd_ssh_keygen()
55
local cur prev words cword comp_args
66
_comp_initialize -n := -- "$@" || return
77

8+
local noargopts='!(-*|*[ aCIJjMNPSVWzbEFRDwfGKsTmnOrtY]*)'
9+
# shellcheck disable=SC2254
810
case $prev in
9-
-*[aCIJjMNPSVWz])
11+
-${noargopts}[aCIJjMNPSVWz])
1012
return
1113
;;
12-
-*b)
14+
-${noargopts}b)
1315
local -a sizes=()
1416
case "${words[*]}" in
1517
*" -t dsa"?( *))
@@ -26,28 +28,28 @@ _comp_cmd_ssh_keygen()
2628
_comp_compgen -- -W '"${sizes[@]}"'
2729
return
2830
;;
29-
-*E)
31+
-${noargopts}E)
3032
_comp_compgen -- -W 'md5 sha256'
3133
return
3234
;;
33-
-*[FR])
35+
-${noargopts}[FR])
3436
# TODO: trim this down to actual entries in known hosts files
3537
_comp_compgen_known_hosts -- "$cur"
3638
return
3739
;;
38-
-*[Dw])
40+
-${noargopts}[Dw])
3941
_comp_compgen_filedir so
4042
return
4143
;;
42-
-*[fGKsT])
44+
-${noargopts}[fGKsT])
4345
_comp_compgen_filedir
4446
return
4547
;;
46-
-*m)
48+
-${noargopts}m)
4749
_comp_compgen -- -W 'PEM PKCS8 RFC4716'
4850
return
4951
;;
50-
-*n)
52+
-${noargopts}n)
5153
[[ ${words[*]} != *\ -*Y\ * ]] || return
5254
if [[ ${words[*]} == *\ -*h\ * ]]; then
5355
_comp_compgen_known_hosts -- "${cur##*,}"
@@ -58,20 +60,20 @@ _comp_cmd_ssh_keygen()
5860
fi
5961
return
6062
;;
61-
-*O)
63+
-${noargopts}O)
6264
if [[ $cur != *=* ]]; then
6365
local -a opts=()
6466
case ${words[*]} in
65-
*\ -*M\ *)
67+
*\ -${noargopts}M\ *)
6668
opts=(
6769
lines= start-line= checkpoint= memory= start=
6870
generator=
6971
)
7072
;;
71-
*\ -*r\ *)
73+
*\ -${noargopts}r\ *)
7274
opts=(hashalg=)
7375
;;
74-
*\ -*s\ *)
76+
*\ -${noargopts}s\ *)
7577
opts=(
7678
clear critical: extension: force-command=
7779
no-agent-forwarding no-port-forwarding no-pty
@@ -81,13 +83,13 @@ _comp_cmd_ssh_keygen()
8183
source-address= verify-required
8284
)
8385
;;
84-
*\ -*t\ +([a-z0-9])-sk\ *)
86+
*\ -${noargopts}t\ +([a-z0-9])-sk\ *)
8587
opts=(
8688
application= challenge= device= no-touch-required
8789
resident user= verify-required write-attestation=
8890
)
8991
;;
90-
*\ -*Y\ *)
92+
*\ -${noargopts}Y\ *)
9193
opts=(hashalg= print-pubkey verify-time)
9294
;;
9395
esac
@@ -129,11 +131,11 @@ _comp_cmd_ssh_keygen()
129131
fi
130132
return
131133
;;
132-
-*r)
133-
[[ ${words[*]} != *\ -*Y\ * ]] || _comp_compgen_filedir
134+
-${noargopts}r)
135+
[[ ${words[*]} != *\ -${noargopts}Y\ * ]] || _comp_compgen_filedir
134136
return
135137
;;
136-
-*t)
138+
-${noargopts}t)
137139
# Prefer `ssh` from same dir for resolving options, etc
138140
local pathcmd protocols
139141
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
@@ -145,7 +147,7 @@ _comp_cmd_ssh_keygen()
145147
_comp_compgen -- -W "$types"
146148
return
147149
;;
148-
-*Y)
150+
-${noargopts}Y)
149151
_comp_compgen -- -W 'find-principals check-novalidate sign verify'
150152
return
151153
;;
@@ -157,7 +159,7 @@ _comp_cmd_ssh_keygen()
157159
_comp_compgen_help -- "-?" # OpenSSH < 7
158160
fi
159161

160-
if [[ ${words[*]} == *\ -*s\ * ]]; then
162+
if [[ ${words[*]} == *\ -${noargopts}s\ * ]]; then
161163
_comp_compgen -a filedir pub
162164
fi
163165
} &&

0 commit comments

Comments
 (0)