From: Fionn Fitzmaurice Date: Sun, 28 Jun 2026 17:04:55 +0000 (+0000) Subject: patch 9.2.0742: filetype: SSH keys and related filetypes not recognized X-Git-Tag: v9.2.0742^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e66ebc0fdd7804db4baa076e62c78d208adaeaf;p=thirdparty%2Fvim.git patch 9.2.0742: filetype: SSH keys and related filetypes not recognized Problem: filetype: SSH keys and related filetypes not recognized Solution: Detect sshpublickey, sshknownhosts sshauthorizedkeys and sshallowedsigners filetypes, add syntax scripts for those filetypes (Fionn Fitzmaurice) This adds syntax highlighting for SSH public keys, as well as related filetypes derived from this (SSH authorized keys, SSH known hosts and SSH allowed signers). Also add filetype detection based on the path and name. closes: #20635 Signed-off-by: Fionn Fitzmaurice Signed-off-by: Christian Brabandt --- diff --git a/.github/MAINTAINERS b/.github/MAINTAINERS index f2200c4ac6..0afec653f2 100644 --- a/.github/MAINTAINERS +++ b/.github/MAINTAINERS @@ -699,8 +699,12 @@ runtime/syntax/sqloracle.vim @chrisbra runtime/syntax/squirrel.vim @zenmatic runtime/syntax/srt.vim @ObserverOfTime runtime/syntax/ssa.vim @ObserverOfTime +runtime/syntax/sshallowedsigners.vim @fionn +runtime/syntax/sshauthorizedkeys.vim @fionn runtime/syntax/sshconfig.vim @Jakuje runtime/syntax/sshdconfig.vim @Jakuje +runtime/syntax/sshpublickey.vim @fionn +runtime/syntax/sshknownhosts.vim @fionn runtime/syntax/sudoers.vim @e-kwsm runtime/syntax/svn.vim @hdima runtime/syntax/swayconfig.vim @jamespeapen diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 7a39bdd8bf..d4baad6d8c 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1107,6 +1107,12 @@ au BufNewFile,BufRead */etc/ssh/ssh_config.d/*.conf setf sshconfig " OpenSSH server configuration au BufNewFile,BufRead */etc/ssh/sshd_config.d/*.conf setf sshdconfig +" OpenSSH public keys, authorized keys, signing keys, host keys +au BufNewFile,BufRead */.ssh/?*.pub,/etc/ssh/?*.pub setf sshpublickey +au BufNewFile,BufRead */.ssh/authorized_keys setf sshauthorizedkeys +au BufNewFile,BufRead */.ssh/known_hosts,/etc/ssh/ssh_known_hosts setf sshknownhosts +au BufNewFile,BufRead allowed_signers,*.allowed_signers setf sshallowedsigners + " OpenVPN configuration au BufNewFile,BufRead */openvpn/*/*.conf setf openvpn diff --git a/runtime/syntax/sshallowedsigners.vim b/runtime/syntax/sshallowedsigners.vim new file mode 100644 index 0000000000..8392747e8a --- /dev/null +++ b/runtime/syntax/sshallowedsigners.vim @@ -0,0 +1,31 @@ +" Vim syntax file +" Language: OpenSSH allowed signers file +" Author: Fionn Fitzmaurice (github.com/fionn) +" Maintainer: Fionn Fitzmaurice (github.com/fionn) +" License: Vim & Apache 2.0 + +if exists("b:current_syntax") + finish +endif + +syn match sshAllowedSignersPrincipal "!\?[a-zA-Z0-9.*?_+-]\+@[a-zA-Z0-9.*?-]\+" nextgroup=sshAllowedSignersPrincipalSeparator,sshAllowedSignersOptions,sshKeyType skipwhite +syn match sshAllowedSignersPrincipalSeparator "," contained nextgroup=sshAllowedSignersPrincipal + +syn region sshAllowedSignersOptions start="[a-z]" end="\s\@=" contains=@sshAllowedSignersOption nextgroup=sshKeyType skipwhite oneline contained +syn cluster sshAllowedSignersOption contains=sshAllowedSignersOptionKeyword,sshAllowedSignersOptionSeparator,sshAllowedSignersOptionAssignment,sshAllowedSignersOptionValue +syn keyword sshAllowedSignersOptionKeyword namespaces cert-authority valid-after valid-before contained +syn match sshAllowedSignersOptionSeparator "," contained +syn match sshAllowedSignersOptionAssignment "=" contained +syn match sshAllowedSignersOptionValue '"\(\\\"\|[^"]\)*"' contained + +runtime! syntax/sshpublickey.vim + +hi def link sshAllowedSignersPrincipal Identifier +hi def link sshAllowedSignersPrincipalSeparator Punctuation + +hi def link sshAllowedSignersOptionKeyword Keyword +hi def link sshAllowedSignersOptionSeparator Punctuation +hi def link sshAllowedSignersOptionAssignment Operator +hi def link sshAllowedSignersOptionValue String + +let b:current_syntax = "sshallowedsigners" diff --git a/runtime/syntax/sshauthorizedkeys.vim b/runtime/syntax/sshauthorizedkeys.vim new file mode 100644 index 0000000000..cf6b912fbc --- /dev/null +++ b/runtime/syntax/sshauthorizedkeys.vim @@ -0,0 +1,25 @@ +" Vim syntax file +" Language: OpenSSH authorized keys file +" Author: Fionn Fitzmaurice (github.com/fionn) +" Maintainer: Fionn Fitzmaurice (github.com/fionn) +" License: Vim & Apache 2.0 + +if exists("b:current_syntax") + finish +endif + +syn region sshAuthorizedKeyOptions start="^[a-z]" end="\s" contains=@sshAuthorizedKeyOption nextgroup=sshKeyType skipwhite oneline +syn cluster sshAuthorizedKeyOption contains=sshAuthorizedKeyOptionKeyword,sshAuthorizedKeyOptionSeparator,sshAuthorizedKeyOptionAssignment,sshAuthorizedKeyOptionValue +syn match sshAuthorizedKeyOptionKeyword "[a-z-]\+" contained +syn match sshAuthorizedKeyOptionSeparator "," contained +syn match sshAuthorizedKeyOptionAssignment "=" contained +syn match sshAuthorizedKeyOptionValue '"\(\\\"\|[^"]\)*"' contained + +runtime! syntax/sshpublickey.vim + +hi def link sshAuthorizedKeyOptionKeyword Keyword +hi def link sshAuthorizedKeyOptionSeparator Punctuation +hi def link sshAuthorizedKeyOptionAssignment Operator +hi def link sshAuthorizedKeyOptionValue String + +let b:current_syntax = "sshauthorizedkeys" diff --git a/runtime/syntax/sshknownhosts.vim b/runtime/syntax/sshknownhosts.vim new file mode 100644 index 0000000000..5d41deb79b --- /dev/null +++ b/runtime/syntax/sshknownhosts.vim @@ -0,0 +1,27 @@ +" Vim syntax file +" Language: OpenSSH known hosts file +" Author: Fionn Fitzmaurice (github.com/fionn) +" Maintainer: Fionn Fitzmaurice (github.com/fionn) +" License: Vim & Apache 2.0 + +if exists("b:current_syntax") + finish +endif + +runtime! syntax/sshpublickey.vim + +syn match sshKnownHostsMarker "^@cert-authority\>" nextgroup=sshKnownHostsHostname,sshKnownHostsHashedHostname skipwhite +syn match sshKnownHostsMarker "^@revoked\>" nextgroup=sshKnownHostsHostname,sshKnownHostsHashedHostname skipwhite + +syn match sshKnownHostsHostname "!\?[a-zA-Z0-9.*-]\+" nextgroup=sshKnownHostsHostnameSeparator,sshKeyType skipwhite +syn match sshKnownHostsHostname "!\?\[[a-zA-Z0-9.*-]\+\]:[0-9]\{1,5}" nextgroup=sshKnownHostsHostnameSeparator,sshKeyType skipwhite +syn match sshKnownHostsHostnameSeparator "," contained nextgroup=sshKnownHostsHostname + +syn match sshKnownHostsHashedHostname "|1|[a-zA-Z0-9/+]\+=\{,2}|[a-zA-Z0-9/+]\+=\{,2}" nextgroup=sshKeyType skipwhite + +hi def link sshKnownHostsMarker Statement +hi def link sshKnownHostsHostname Identifier +hi def link sshKnownHostsHostnameSeparator Punctuation +hi def link sshKnownHostsHashedHostname Identifier + +let b:current_syntax = "sshknownhosts" diff --git a/runtime/syntax/sshpublickey.vim b/runtime/syntax/sshpublickey.vim new file mode 100644 index 0000000000..200378ae0e --- /dev/null +++ b/runtime/syntax/sshpublickey.vim @@ -0,0 +1,30 @@ +" Vim syntax file +" Language: OpenSSH public key +" Author: Fionn Fitzmaurice (github.com/fionn) +" Maintainer: Fionn Fitzmaurice (github.com/fionn) +" License: Vim & Apache 2.0 + +if exists("b:current_syntax") + finish +endif + +setlocal iskeyword=_,.,@-@,-,a-z,A-Z,48-57 + +syn keyword sshKeyType ssh-ed25519 nextgroup=sshKeyBase64Encoded skipwhite +syn keyword sshKeyType sk-ssh-ed25519@openssh.com nextgroup=sshKeyBase64Encoded skipwhite +syn keyword sshKeyType ecdsa-sha2-nistp256 nextgroup=sshKeyBase64Encoded skipwhite +syn keyword sshKeyType ecdsa-sha2-nistp384 nextgroup=sshKeyBase64Encoded skipwhite +syn keyword sshKeyType ecdsa-sha2-nistp521 nextgroup=sshKeyBase64Encoded skipwhite +syn keyword sshKeyType sk-ecdsa-sha2-nistp256@openssh.com nextgroup=sshKeyBase64Encoded skipwhite +syn keyword sshKeyType ssh-rsa nextgroup=sshKeyBase64Encoded skipwhite + +syn match sshKeyBase64Encoded "AAAA[a-zA-Z0-9/+]\{64,8000}=\{,2}" contained nextgroup=sshKeyComment +syn match sshKeyComment ".*$" contained + +syn match sshKeyComment "#.*$" + +hi def link sshKeyType Type +hi def link sshKeyBase64Encoded String +hi def link sshKeyComment Comment + +let b:current_syntax = "sshpublickey" diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim index 10a1d07d28..87b640e02d 100644 --- a/src/testdir/test_filetype.vim +++ b/src/testdir/test_filetype.vim @@ -790,8 +790,12 @@ def s:GetFilenameChecks(): dict> srec: ['file.s19', 'file.s28', 'file.s37', 'file.mot', 'file.srec'], srt: ['file.srt'], ssa: ['file.ass', 'file.ssa'], + sshallowedsigners: ['any/allowed_signers', 'any/.allowed_signers', 'any/file.allowed_signers'], + sshauthorizedkeys: ['any/.ssh/authorized_keys'], sshconfig: ['ssh_config', '/.ssh/config', '/etc/ssh/ssh_config.d/file.conf', 'any/etc/ssh/ssh_config.d/file.conf', 'any/.ssh/config', 'any/.ssh/file.conf'], sshdconfig: ['sshd_config', '/etc/ssh/sshd_config.d/file.conf', 'any/etc/ssh/sshd_config.d/file.conf'], + sshpublickey: ['any/.ssh/file.pub', '/etc/ssh/file.pub'], + sshknownhosts: ['any/.ssh/known_hosts', '/etc/ssh/ssh_known_hosts'], st: ['file.st'], starlark: ['file.ipd', 'file.sky', 'file.star', 'file.starlark'], stata: ['file.ado', 'file.do', 'file.imata', 'file.mata'], diff --git a/src/version.c b/src/version.c index ebe7f97093..fe47a6e4e4 100644 --- a/src/version.c +++ b/src/version.c @@ -759,6 +759,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 742, /**/ 741, /**/