Skip to content

Commit

Permalink
fix(ssh-keygen): suggest -O arg completions depending on mode
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 2, 2024
1 parent 4c9fc87 commit b49ab1d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
38 changes: 27 additions & 11 deletions completions/ssh-keygen
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,33 @@ _comp_cmd_ssh_keygen()
;;
-*O)
if [[ $cur != *=* ]]; then
_comp_compgen -- -W 'clear critical: extension: force-command=
no-agent-forwarding no-port-forwarding no-pty no-user-rc
no-x11-forwarding permit-agent-forwarding
permit-port-forwarding permit-pty permit-user-rc
permit-X11-forwarding no-touch-required source-address=
verify-required
lines= start-line= checkpoint= memory= start= generator=
application= challenge= device= no-touch-required resident
user= write-attestation='
local -a opts=()
case ${words[*]} in
*\ -*M\ *)
opts=(
lines= start-line= checkpoint= memory= start=
generator=
)
;;
*\ -*s\ *)
opts=(
clear critical: extension: force-command=
no-agent-forwarding no-port-forwarding no-pty
no-user-rc no-x11-forwarding permit-agent-forwarding
permit-port-forwarding permit-pty permit-user-rc
permit-X11-forwarding no-touch-required
source-address= verify-required
)
;;
*\ -*t\ +([a-z0-9])-sk\ *)
opts=(
application= challenge= device= no-touch-required
resident user= verify-required write-attestation=
)
;;
esac
((${#opts[@]})) &&
_comp_compgen -- -W '"${opts[@]}"'

[[ ${COMPREPLY-} == *[:=] ]] && compopt -o nospace
_comp_ltrim_colon_completions "$cur"
Expand Down
18 changes: 12 additions & 6 deletions test/t/test_ssh_keygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ def test_ecdsa_sk_b(self, completion):
assert not completion

@pytest.mark.complete("ssh-keygen -O ")
def test_O(self, completion):
def test_bare_O(self, completion):
assert not completion

@pytest.mark.complete("ssh-keygen -s -O ")
def test_s_O(self, completion):
assert completion
assert any(x.endswith("=") for x in completion)

@pytest.mark.complete("ssh-keygen -O force-command=bas")
@pytest.mark.complete("ssh-keygen -s -O force-command=bas")
def test_O_force_command(self, completion):
assert completion
assert not completion.startswith("force-command=")
Expand All @@ -68,18 +72,20 @@ def test_O_force_command(self, completion):
def test_O_unknown(self, completion):
assert not completion

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

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

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

@pytest.mark.complete("ssh-keygen -O application=nonexistent")
@pytest.mark.complete(
"ssh-keygen -t ed25519-sk -O application=nonexistent"
)
def test_O_application_nonexistent(self, completion):
assert not completion

0 comments on commit b49ab1d

Please sign in to comment.