diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2023-04-22 20:42:34 +0200 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2023-04-22 20:42:34 +0200 |
| commit | b91bb045f335eb2e15bebc5fa108e5893b5d9951 (patch) | |
| tree | 63491f4773069755ed5b8f5d344b202b34f23bc6 /fnl/conf/filetype.fnl | |
| parent | 1b6566231b8bfc8223fcbf11d1243d9328f65f4f (diff) | |
small things
Diffstat (limited to 'fnl/conf/filetype.fnl')
| -rw-r--r-- | fnl/conf/filetype.fnl | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/fnl/conf/filetype.fnl b/fnl/conf/filetype.fnl new file mode 100644 index 0000000..29f64b0 --- /dev/null +++ b/fnl/conf/filetype.fnl @@ -0,0 +1,44 @@ +(fn playbook? [filename] + (P filename) + (local pattern (vim.regex :^playbook.*)) + (pattern:match_str filename)) + +(fn group-vars? [relative-dir] + (local pattern (vim.regex :group_vars$)) + (pattern:match_str relative-dir)) + +(fn roles? [relative-dir] + (local pattern (vim.regex :roles$)) + (pattern:match_str relative-dir)) + +(fn task? [relative-file] + (local pattern (vim.regex :.*tasks.*)) + (pattern:match_str relative-file)) + +(fn ansible-files? [items] + (local [item & rest] items) + (if (not item) :yaml + (task? item) :yaml.ansible + (roles? item) :yaml.ansible + (group-vars? item) :yaml.ansible + (ansible-files? rest))) + +(fn yaml-filetype [path buf] + (local [repo?] + (vim.fs.find :.git + {:upward true + :path (vim.fs.dirname path) + :stop (vim.fs.dirname (vim.loop.cwd))})) + (local files (or (not repo?) (icollect [path file-or-dir (vim.fs.dir (vim.fs.dirname repo?) + {:skip #(not= "." + ($1:sub 1 + 1)) + :depth 2})] + (do + path)))) + (if (and repo? (playbook? (vim.fn.fnamemodify path ":t"))) :yaml.ansible + (and repo? (task? (vim.fn.fnamemodify path ":."))) :yaml.ansible + repo? (ansible-files? files) + :yaml)) + +(vim.filetype.add {:extension {:yml yaml-filetype :yaml yaml-filetype}}) |
