blob: b740f28a0e62f19516709e5dd8632d7ecdbbc0eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
---@return function string
local getPasswordFactory = function()
local bufferPasswordMap = {}
return function()
local key = string.format("%s", vim.fn.bufnr())
if bufferPasswordMap[key] == nil then
password = vim.fn.inputsecret("Enter password: ")
bufferPasswordMap[key] = password
end
return bufferPasswordMap[key]
end
end
local getPassword = getPasswordFactory()
local ENCRYPTED_PREFIX = "# <<<encrypted>>>"
---@enum buftype
local BUFTYPE = {
encrypted = 1,
plaintext = 2,
}
local function bufferEncrypted()
local first_line = vim.api.nvim_buf_get_lines(0, 0, 1, false)[1]
if first_line == ENCRYPTED_PREFIX then
return true
end
end
return {
getPassword = getPassword,
ENCRYPTED_PREFIX = ENCRYPTED_PREFIX,
BUFTYPE = BUFTYPE,
bufferEncrypted = bufferEncrypted,
}
|