-- augroup utility function
--
-- Let's you create and use autogroups through lua
-- which (as of now) is not possible through official nvim api
--
-- Cribbed from the very helpful https://icyphox.sh/blog/nvim-lua - Thank you!
--
-- Example usage settings.lua
-- local cmd = vim.cmd
-- local u = require('utils')
-- u.create_augroup({
--     { 'BufRead,BufNewFile', '/tmp/nail-*', 'setlocal', 'ft=mail' },
--     { 'BufRead,BufNewFile', '*s-nail-*', 'setlocal', 'ft=mail' },
-- }, 'ftmail')
-- cmd('au BufNewFile,BufRead * if &ft == "" | set ft=text | endif')

local cmd = vim.cmd


return function(cmds, groupname)
    cmd('augroup ' .. groupname)
    cmd('autocmd!')
    for _, autocmd in ipairs(cmds) do
        cmd('autocmd ' .. table.concat(autocmd, ' '))
    end
    cmd('augroup END')
end
