This commit is contained in:
sankalp committed 2026-03-30 13:36:26 +05:45
1 parent e21e351c98
commit ffd20f5ebf
2 files changed
+58 -58

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@
"mason-nvim-lint": { "branch": "main", "commit": "767b8ccdddaa977bec8987fd7507b9865a279235" }, "mason-nvim-lint": { "branch": "main", "commit": "767b8ccdddaa977bec8987fd7507b9865a279235" },
"mason.nvim": { "branch": "main", "commit": "44d1e90e1f66e077268191e3ee9d2ac97cc18e65" }, "mason.nvim": { "branch": "main", "commit": "44d1e90e1f66e077268191e3ee9d2ac97cc18e65" },
"mdx.nvim": { "branch": "main", "commit": "30222997ed4c0c7cc7447c4fce360fce87101bbf" }, "mdx.nvim": { "branch": "main", "commit": "30222997ed4c0c7cc7447c4fce360fce87101bbf" },
"mini.nvim": { "branch": "main", "commit": "debd726e1b620e9934d554c2772de2e99cd3ccbe" }, "mini.nvim": { "branch": "main", "commit": "af5f75c9ce572a4d1f0c77d6fb4ea764d16c1b3c" },
"neogen": { "branch": "main", "commit": "23e7e9f883d01289ebd90e98025acc860ea26366" }, "neogen": { "branch": "main", "commit": "23e7e9f883d01289ebd90e98025acc860ea26366" },
"neoscroll.nvim": { "branch": "master", "commit": "c8d29979cb0cb3a2437a8e0ae683fd82f340d3b8" }, "neoscroll.nvim": { "branch": "master", "commit": "c8d29979cb0cb3a2437a8e0ae683fd82f340d3b8" },
"nvim-autopairs": { "branch": "master", "commit": "59bce2eef357189c3305e25bc6dd2d138c1683f5" }, "nvim-autopairs": { "branch": "master", "commit": "59bce2eef357189c3305e25bc6dd2d138c1683f5" },
+57 -57
View File
@@ -3,63 +3,63 @@ local function augroup(name)
end end
-- hide sensetive data in .env -- hide sensetive data in .env
local group = vim.api.nvim_create_augroup('EnvMask', { clear = true }) -- local group = vim.api.nvim_create_augroup('EnvMask', { clear = true })
local hidden = {} -- local hidden = {}
--
local function mask_line(line) -- local function mask_line(line)
if line:match('^%s*#') or line:match('^%s*$') then -- if line:match('^%s*#') or line:match('^%s*$') then
return line -- return line
end -- end
--
local key, value = line:match('^([%w_]+)%s*=%s*(.*)') -- local key, value = line:match('^([%w_]+)%s*=%s*(.*)')
if not key or not value then -- if not key or not value then
return line -- return line
end -- end
--
return key .. '=' .. string.rep('*', #value) -- return key .. '=' .. string.rep('*', #value)
end -- end
--
local function hide(buf) -- local function hide(buf)
if hidden[buf] then -- if hidden[buf] then
return -- return
end -- end
--
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false) -- local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
hidden[buf] = lines -- hidden[buf] = lines
--
local masked = {} -- local masked = {}
for i, line in ipairs(lines) do -- for i, line in ipairs(lines) do
masked[i] = mask_line(line) -- masked[i] = mask_line(line)
end -- end
--
vim.api.nvim_buf_set_lines(buf, 0, -1, false, masked) -- vim.api.nvim_buf_set_lines(buf, 0, -1, false, masked)
end -- end
--
local function show(buf) -- local function show(buf)
if not hidden[buf] then -- if not hidden[buf] then
return -- return
end -- end
vim.api.nvim_buf_set_lines(buf, 0, -1, false, hidden[buf]) -- vim.api.nvim_buf_set_lines(buf, 0, -1, false, hidden[buf])
hidden[buf] = nil -- hidden[buf] = nil
end -- end
--
vim.api.nvim_create_autocmd('BufReadPost', { -- vim.api.nvim_create_autocmd('BufReadPost', {
group = group, -- group = group,
pattern = { '.env', '.env.*', '*.env' }, -- pattern = { '.env', '.env.*', '*.env' },
callback = function(args) -- callback = function(args)
vim.cmd('silent! noautocmd redraw') -- vim.cmd('silent! noautocmd redraw')
hide(args.buf) -- hide(args.buf)
end, -- end,
}) -- })
--
vim.keymap.set('n', '<leader>ot', function() -- vim.keymap.set('n', '<leader>ot', function()
local buf = vim.api.nvim_get_current_buf() -- local buf = vim.api.nvim_get_current_buf()
if hidden[buf] then -- if hidden[buf] then
show(buf) -- show(buf)
else -- else
hide(buf) -- hide(buf)
end -- end
end, { desc = 'Toggle env masking' }) -- end, { desc = 'Toggle env masking' })
-- Strip trailing spaces before write -- Strip trailing spaces before write
vim.api.nvim_create_autocmd({ 'BufWritePre' }, { vim.api.nvim_create_autocmd({ 'BufWritePre' }, {