let the user view .envrc before approval

This commit is contained in:
raf 2025-06-09 14:48:26 +03:00
commit e962f02437
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -2,7 +2,7 @@ local M = {}
---@class DirenvConfig
---@field bin string Path to direnv executable
--- @field autoload_direnv boolean Automatically load direnv when opening files
---@field autoload_direnv boolean|string Automatically load direnv when opening files. true/false or "confirm" to show file first
---@field cache_ttl integer Cache TTL in milliseconds for direnv status checks
---@field statusline table Configuration for statusline integration
---@field statusline.enabled boolean Enable statusline integration
@ -405,6 +405,21 @@ M.check_direnv = function()
end
-- Status 1 means the .envrc file needs approval
if M.config.autoload_direnv == "confirm" then
vim.schedule(function()
vim.cmd("edit " .. path)
vim.defer_fn(function()
local choice = vim.fn.confirm(
"Load environment from " .. path .. "?",
"&Yes\n&No",
1
)
if choice == 1 then
M.allow_direnv()
end
end, 100)
end)
else
vim.schedule(function()
local choice = vim.fn.confirm(
path .. " is not allowed by direnv. What would you like to do?",
@ -420,6 +435,7 @@ M.check_direnv = function()
-- Ignore means do nothing
end)
end
end
M._get_rc_status(on_exit)
end