Skip to content

Commit b49ab1d

Browse files
committed
fix(ssh-keygen): suggest -O arg completions depending on mode
1 parent 4c9fc87 commit b49ab1d

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

completions/ssh-keygen

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,33 @@ _comp_cmd_ssh_keygen()
6060
;;
6161
-*O)
6262
if [[ $cur != *=* ]]; then
63-
_comp_compgen -- -W 'clear critical: extension: force-command=
64-
no-agent-forwarding no-port-forwarding no-pty no-user-rc
65-
no-x11-forwarding permit-agent-forwarding
66-
permit-port-forwarding permit-pty permit-user-rc
67-
permit-X11-forwarding no-touch-required source-address=
68-
verify-required
69-
70-
lines= start-line= checkpoint= memory= start= generator=
71-
72-
application= challenge= device= no-touch-required resident
73-
user= write-attestation='
63+
local -a opts=()
64+
case ${words[*]} in
65+
*\ -*M\ *)
66+
opts=(
67+
lines= start-line= checkpoint= memory= start=
68+
generator=
69+
)
70+
;;
71+
*\ -*s\ *)
72+
opts=(
73+
clear critical: extension: force-command=
74+
no-agent-forwarding no-port-forwarding no-pty
75+
no-user-rc no-x11-forwarding permit-agent-forwarding
76+
permit-port-forwarding permit-pty permit-user-rc
77+
permit-X11-forwarding no-touch-required
78+
source-address= verify-required
79+
)
80+
;;
81+
*\ -*t\ +([a-z0-9])-sk\ *)
82+
opts=(
83+
application= challenge= device= no-touch-required
84+
resident user= verify-required write-attestation=
85+
)
86+
;;
87+
esac
88+
((${#opts[@]})) &&
89+
_comp_compgen -- -W '"${opts[@]}"'
7490

7591
[[ ${COMPREPLY-} == *[:=] ]] && compopt -o nospace
7692
_comp_ltrim_colon_completions "$cur"

test/t/test_ssh_keygen.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ def test_ecdsa_sk_b(self, completion):
5555
assert not completion
5656

5757
@pytest.mark.complete("ssh-keygen -O ")
58-
def test_O(self, completion):
58+
def test_bare_O(self, completion):
59+
assert not completion
60+
61+
@pytest.mark.complete("ssh-keygen -s -O ")
62+
def test_s_O(self, completion):
5963
assert completion
6064
assert any(x.endswith("=") for x in completion)
6165

62-
@pytest.mark.complete("ssh-keygen -O force-command=bas")
66+
@pytest.mark.complete("ssh-keygen -s -O force-command=bas")
6367
def test_O_force_command(self, completion):
6468
assert completion
6569
assert not completion.startswith("force-command=")
@@ -68,18 +72,20 @@ def test_O_force_command(self, completion):
6872
def test_O_unknown(self, completion):
6973
assert not completion
7074

71-
@pytest.mark.complete("ssh-keygen -O application=")
75+
@pytest.mark.complete("ssh-keygen -t ed25519-sk -O application=")
7276
def test_O_application(self, completion):
7377
assert completion == "ssh:"
7478

75-
@pytest.mark.complete("ssh-keygen -O application=s")
79+
@pytest.mark.complete("ssh-keygen -t ed25519-sk -O application=s")
7680
def test_O_application_s(self, completion):
7781
assert completion == "sh:"
7882

79-
@pytest.mark.complete("ssh-keygen -O application=ssh:")
83+
@pytest.mark.complete("ssh-keygen -t ed25519-sk -O application=ssh:")
8084
def test_O_application_ssh_colon(self, completion):
8185
assert not completion
8286

83-
@pytest.mark.complete("ssh-keygen -O application=nonexistent")
87+
@pytest.mark.complete(
88+
"ssh-keygen -t ed25519-sk -O application=nonexistent"
89+
)
8490
def test_O_application_nonexistent(self, completion):
8591
assert not completion

0 commit comments

Comments
 (0)