From 491f733221ac5ae6444589350361a800976e536f Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Tue, 1 Aug 2023 14:21:19 +0300 Subject: [PATCH] feat(nvim): ansible document support --- config/astronvim/lua/user/init.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/config/astronvim/lua/user/init.lua b/config/astronvim/lua/user/init.lua index 0925249..829b4a2 100644 --- a/config/astronvim/lua/user/init.lua +++ b/config/astronvim/lua/user/init.lua @@ -79,6 +79,29 @@ return { -- augroups/autocommands and custom filetypes also this just pure lua so -- anything that doesn't fit in the normal config locations above can go here polish = function() + local function yaml_ft(path, bufnr) + -- get content of buffer as string + local content = vim.filetype.getlines(bufnr) + if type(content) == "table" then content = table.concat(content, "\n") end + + -- check if file is in roles, tasks, or handlers folder + local path_regex = vim.regex "(tasks\\|roles\\|handlers)/" + if path_regex and path_regex:match_str(path) then return "yaml.ansible" end + -- check for known ansible playbook text and if found, return yaml.ansible + local regex = vim.regex "hosts:\\|tasks:" + if regex and regex:match_str(content) then return "yaml.ansible" end + + -- return yaml if nothing else + return "yaml" + end + + vim.filetype.add { + extension = { + yml = yaml_ft, + yaml = yaml_ft, + }, + } + require("notify").setup({ background_colour = "#000000", })