refactor(nvim): ensure passage files aren't backed up

This commit is contained in:
Price Hiller 2024-03-01 05:16:31 -06:00
parent d3528370bd
commit c8a2092475
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
2 changed files with 25 additions and 1 deletions

View File

@ -141,7 +141,8 @@ M.setup = function()
opt.exrc = true
-- Backups
opt.backupdir = vim.fn.stdpath('state') .. "/backup//"
opt.backupdir = vim.fn.stdpath("state") .. "/backup//"
opt.backupskip = opt.backupskip + "*/*passage.*"
opt.backup = true
end

View File

@ -0,0 +1,23 @@
local M = {}
local augroup = vim.api.nvim_create_augroup("user-autocmds", { clear = false })
vim.api.nvim_create_autocmd("BufReadPre", {
group = augroup,
desc = "Ensure backupskip files do not leave anything behind",
pattern = vim.opt.backupskip:get(),
callback = function(args)
---@type integer
local bufnr = args.buf
vim.iter({
"swapfile",
"undofile",
}):each(function(opt)
vim.api.nvim_set_option_value(opt, false, {
buf = bufnr,
})
end)
end,
})
return M