Skip to content

Commit 0984db6

Browse files
committed
ssh: make option completion case insensitive
1 parent 8d2c976 commit 0984db6

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

completions/ssh

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ _ssh_options()
6363
fi
6464

6565
compopt -o nospace
66-
COMPREPLY=( $(compgen -S = -W '${opts[@]}' -- "$cur" ) )
66+
local IFS=$' \t\n' reset=$(shopt -p nocasematch); shopt -s nocasematch
67+
local option
68+
COMPREPLY=( $(for option in "${opts[@]}"; do
69+
[[ $option == "$cur"* ]] && printf '%s=\n' "$option"
70+
done) )
71+
$reset
6772
}
6873

6974
# Complete a ssh suboption (like ForwardAgent=y<tab>)
@@ -76,85 +81,85 @@ _ssh_suboption()
7681
# Split into subopt and subval
7782
local prev=${1%%=*} cur=${1#*=}
7883

79-
case $prev in
80-
BatchMode|CanonicalDomains|CanonicalizeFallbackLocal|\
81-
ChallengeResponseAuthentication|CheckHostIP|\
82-
ClearAllForwardings|ControlPersist|Compression|EnableSSHKeysign|\
83-
ExitOnForwardFailure|ForwardAgent|ForwardX11|ForwardX11Trusted|\
84-
GatewayPorts|GSSAPIAuthentication|GSSAPIKeyExchange|\
85-
GSSAPIDelegateCredentials|GSSAPIRenewalForcesRekey|GSSAPITrustDns|\
86-
HashKnownHosts|HostbasedAuthentication|IdentitiesOnly|\
87-
KbdInteractiveAuthentication|KbdInteractiveDevices|\
88-
NoHostAuthenticationForLocalhost|PasswordAuthentication|\
89-
ProxyUseFdpass|PubkeyAuthentication|RhostsRSAAuthentication|\
90-
RSAAuthentication|StrictHostKeyChecking|StreamLocalBindUnlink|\
91-
TCPKeepAlive|UsePrivilegedPort|VerifyHostKeyDNS|VisualHostKey)
84+
case ${prev,,} in
85+
batchmode|canonicaldomains|canonicalizefallbacklocal|\
86+
challengeresponseauthentication|checkhostip|\
87+
clearallforwardings|controlpersist|compression|enablesshkeysign|\
88+
exitonforwardfailure|forwardagent|forwardx11|forwardx11trusted|\
89+
gatewayports|gssapiauthentication|gssapikeyexchange|\
90+
gssapidelegatecredentials|gssapirenewalforcesrekey|gssapitrustdns|\
91+
hashknownhosts|hostbasedauthentication|identitiesonly|\
92+
kbdinteractiveauthentication|kbdinteractivedevices|\
93+
nohostauthenticationforlocalhost|passwordauthentication|\
94+
proxyusefdpass|pubkeyauthentication|rhostsrsaauthentication|\
95+
rsaauthentication|stricthostkeychecking|streamlocalbindunlink|\
96+
tcpkeepalive|useprivilegedport|verifyhostkeydns|visualhostkey)
9297
COMPREPLY=( $(compgen -W 'yes no' -- "$cur") )
9398
;;
94-
AddKeysToAgent)
99+
addkeystoagent)
95100
COMPREPLY=( $(compgen -W 'yes ask confirm no' -- "$cur") )
96101
;;
97-
AddressFamily)
102+
addressfamily)
98103
COMPREPLY=( $(compgen -W 'any inet inet6' -- "$cur") )
99104
;;
100-
BindAddress)
105+
bindaddress)
101106
_ip_addresses
102107
;;
103-
CanonicalizeHostname)
108+
canonicalizehostname)
104109
COMPREPLY=( $(compgen -W 'yes no always' -- "$cur") )
105110
;;
106-
*File|IdentityAgent|Include)
111+
*file|identityagent|include)
107112
_filedir
108113
;;
109-
Cipher)
114+
cipher)
110115
COMPREPLY=( $(compgen -W 'blowfish des 3des' -- "$cur") )
111116
;;
112-
Ciphers)
117+
ciphers)
113118
_ssh_ciphers "$2"
114119
;;
115-
CompressionLevel)
120+
compressionlevel)
116121
COMPREPLY=( $(compgen -W '{1..9}' -- "$cur") )
117122
;;
118-
FingerprintHash)
123+
fingerprinthash)
119124
COMPREPLY=( $(compgen -W 'md5 sha256' -- "$cur") )
120125
;;
121-
IPQoS)
126+
ipqos)
122127
COMPREPLY=( $(compgen -W 'af1{1..4} af2{2..3} af3{1..3} af4{1..3}
123128
cs{0..7} ef lowdelay throughput reliability' -- "$cur") )
124129
;;
125-
HostbasedKeyTypes|HostKeyAlgorithms)
130+
hostbasedkeytypes|hostkeyalgorithms)
126131
COMPREPLY=( $(compgen -W '$(_ssh_query "$2" key)' -- "$cur") )
127132
;;
128-
KexAlgorithms)
133+
kexalgorithms)
129134
COMPREPLY=( $(compgen -W '$(_ssh_query "$2" kex)' -- "$cur") )
130135
;;
131-
MACs)
136+
macs)
132137
_ssh_macs "$2"
133138
;;
134-
PreferredAuthentications)
139+
preferredauthentications)
135140
COMPREPLY=( $(compgen -W 'gssapi-with-mic host-based publickey
136141
keyboard-interactive password' -- "$cur") )
137142
;;
138-
Protocol)
143+
protocol)
139144
COMPREPLY=( $(compgen -W '1 2 1,2 2,1' -- "$cur") )
140145
;;
141-
ProxyJump)
146+
proxyjump)
142147
_known_hosts_real -a -F "$configfile" -- "$cur"
143148
;;
144-
PubkeyAcceptedKeyTypes)
149+
pubkeyacceptedkeytypes)
145150
COMPREPLY=( $(compgen -W '$(_ssh_query "$2" key)' -- "$cur") )
146151
;;
147-
RequestTTY)
152+
requesttty)
148153
COMPREPLY=( $(compgen -W 'no yes force auto' -- "$cur") )
149154
;;
150-
SyslogFacility)
155+
syslogfacility)
151156
COMPREPLY=( $(compgen -W 'DAEMON USER AUTH LOCAL{0..7}' -- "$cur") )
152157
;;
153-
Tunnel)
158+
tunnel)
154159
COMPREPLY=( $(compgen -W 'yes no point-to-point ethernet' \
155160
-- "$cur") )
156161
;;
157-
UpdateHostKeys)
162+
updatehostkeys)
158163
COMPREPLY=( $(compgen -W 'yes no ask' -- "$cur") )
159164
;;
160165
esac

test/t/test_ssh.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ def test_3(self, completion):
2323
@pytest.mark.complete("ssh -vo AddressFamily=")
2424
def test_4(self, completion):
2525
assert completion
26+
27+
@pytest.mark.xfail # TODO our test facilities don't support case change?
28+
@pytest.mark.complete("ssh -vo userknownhostsf")
29+
def test_5(self, completion):
30+
assert "UserKnownHostsFile=" in completion

0 commit comments

Comments
 (0)