mirror of
https://github.com/neovim/neovim.git
synced 2026-06-30 19:57:54 +00:00
vim-patch:9.2.0742: filetype: SSH keys and related filetypes not recognized (#40469)
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: vim/vim#20635
6e66ebc0fd
Co-authored-by: Fionn Fitzmaurice <git@fionn.computer>
This commit is contained in:
@@ -1279,6 +1279,7 @@ local extension = {
|
||||
srt = 'srt',
|
||||
ssa = 'ssa',
|
||||
ass = 'ssa',
|
||||
allowed_signers = 'sshallowedsigners',
|
||||
st = 'st',
|
||||
ipd = 'starlark',
|
||||
sky = 'starlark',
|
||||
@@ -1981,8 +1982,9 @@ local filename = {
|
||||
Snakefile = 'snakemake',
|
||||
['.sqlite_history'] = 'sql',
|
||||
['squid.conf'] = 'squid',
|
||||
['ssh_config'] = 'sshconfig',
|
||||
['sshd_config'] = 'sshdconfig',
|
||||
allowed_signers = 'sshallowedsigners',
|
||||
ssh_config = 'sshconfig',
|
||||
sshd_config = 'sshdconfig',
|
||||
['/etc/sudoers'] = 'sudoers',
|
||||
['sudoers.tmp'] = 'sudoers',
|
||||
['/etc/sysctl.conf'] = 'sysctl',
|
||||
@@ -2181,9 +2183,11 @@ local pattern = {
|
||||
['/etc/slp%.conf$'] = 'slpconf',
|
||||
['/etc/slp%.reg$'] = 'slpreg',
|
||||
['/etc/slp%.spi$'] = 'slpspi',
|
||||
['/etc/sudoers%.d/'] = starsetf('sudoers'),
|
||||
['/etc/ssh/ssh_config%.d/.*%.conf$'] = 'sshconfig',
|
||||
['/etc/ssh/sshd_config%.d/.*%.conf$'] = 'sshdconfig',
|
||||
['^/etc/ssh/ssh_known_hosts$'] = 'sshknownhosts',
|
||||
['^/etc/ssh/.+%.pub$'] = 'sshpublickey',
|
||||
['/etc/sudoers%.d/'] = starsetf('sudoers'),
|
||||
['/etc/sudoers$'] = 'sudoers',
|
||||
['/etc/sysctl%.conf$'] = 'sysctl',
|
||||
['/etc/sysctl%.d/.*%.conf$'] = 'sysctl',
|
||||
@@ -2543,6 +2547,9 @@ local pattern = {
|
||||
['/%.pinforc$'] = 'pinfo',
|
||||
['^${HOME}/%.xinitrc$'] = 'sh',
|
||||
['^${HOME}/%.xserverrc$'] = 'sh',
|
||||
['/%.ssh/authorized_keys$'] = 'sshauthorizedkeys',
|
||||
['/%.ssh/known_hosts$'] = 'sshknownhosts',
|
||||
['/%.ssh/.+%.pub$'] = 'sshpublickey',
|
||||
['/%.cargo/credentials$'] = 'toml',
|
||||
['/%.init/.*%.override$'] = 'upstart',
|
||||
['/%.kube/kuberc$'] = 'yaml',
|
||||
|
||||
31
runtime/syntax/sshallowedsigners.vim
Normal file
31
runtime/syntax/sshallowedsigners.vim
Normal file
@@ -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"
|
||||
25
runtime/syntax/sshauthorizedkeys.vim
Normal file
25
runtime/syntax/sshauthorizedkeys.vim
Normal file
@@ -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"
|
||||
27
runtime/syntax/sshknownhosts.vim
Normal file
27
runtime/syntax/sshknownhosts.vim
Normal file
@@ -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"
|
||||
30
runtime/syntax/sshpublickey.vim
Normal file
30
runtime/syntax/sshpublickey.vim
Normal file
@@ -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"
|
||||
@@ -789,8 +789,12 @@ func s:GetFilenameChecks() abort
|
||||
\ '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'],
|
||||
|
||||
Reference in New Issue
Block a user