.config/nvim/plugin/gpg-encrypted.lua

Sun, 05 May 2024 20:43:54 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Sun, 05 May 2024 20:43:54 -0500
changeset 1162
e6da5f7156c2
parent 1160
28e64ed03c25
child 1166
34bf03fa07e4
permissions
-rw-r--r--

Fix VimEnter/vim_did_enter behavior

local util = require("config.util")

local safe_filter_file = util.safe_filter_file

local g = vim.api.nvim_create_augroup("encrypted", { clear = true })
local filepattern = { "*.gpg", "*.gpg.*" }

local function autocmd(event, opts)
  util.autocmd(g, event, filepattern, opts)
end

autocmd({ "BufReadPre", "FileReadPre" }, {
  command = [[ setl noswapfile noundofile nobackup shada= ]],
})

autocmd("BufReadPost", function(_)
  safe_filter_file("gpg -d")
end)

autocmd("BufWritePre", function(_)
  safe_filter_file("gpg -se -a --default-recipient-self")
end)

autocmd("BufWritePost", { command = [[ silent undo ]] })

mercurial