Add ansible filetype detection

Based on 86eea3d684
This commit is contained in:
Sonny Bakker 2025-02-13 20:49:49 +01:00
parent 5aa08aef39
commit 199f40b0ea
4 changed files with 176 additions and 145 deletions

View file

@ -0,0 +1,40 @@
local ansible_keywords = {
'hosts',
'tasks',
'vars',
'vars_files',
'vars_prompt',
'handlers',
'roles',
'import_tasks',
'import_playbook',
'import_role',
}
vim.filetype.add {
pattern = {
['playbook*.y(a?)ml'] = 'yaml.ansible',
['site*.y(a?)ml'] = 'yaml.ansible',
['inventory*.y(a?)ml'] = 'yaml.ansible',
['task*.y(a?)ml'] = 'yaml.ansible',
['requirement*.y(a?)ml'] = 'yaml.ansible',
['.*/tasks/.*.y(a?)ml'] = 'yaml.ansible',
['.*/vars/.*.y(a?)ml'] = 'yaml.ansible',
['.*/playbooks/.*.y(a?)ml'] = 'yaml.ansible',
['*.ansible.y(a?)ml'] = 'yaml.ansible',
['.*.y(a?)ml'] = {
function(path, bufnr)
local content = vim.api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] or ''
for _, keyword in pairs(ansible_keywords) do
local pattern = string.format('^- %s:', keyword)
if content:match(pattern) then return 'yaml.ansible' end
end
end,
},
},
}