Compare commits

...

3 commits

Author SHA1 Message Date
raf
8962b7fe3f
Merge pull request #22 from NotAShelf/notashelf/push-urpotysrxpxv
Some checks failed
Style & Lint / lint (5.1) (push) Has been cancelled
Style & Lint / style (0.19.1) (push) Has been cancelled
fix: unload environment when changing to diriectory without `.envrc`
2026-05-14 10:24:34 +03:00
be64c2efb7
fix: defer to direnv for env tracking
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6e8b1291ee589ab2f398f24dd7bad1966a6a6964
2026-05-13 11:34:06 +03:00
be0b3fd58f
fix: unload environment when changing to diriectory without .envrc
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I58ab61782a24f87a81d007a49aca1f1d6a6a6964
2026-04-02 10:46:12 +03:00

View file

@ -215,6 +215,50 @@ M.refresh_status = function()
M._get_rc_status(function() end)
end
--- Unload direnv environment by running direnv export in the current directory.
--- direnv handles proper env restoration (including $PATH), unlike manual tracking.
M._unload = function()
local cwd = get_cwd()
if not cwd then
return
end
vim.system(
{ M.config.bin, "export", "json" },
{ text = true, cwd = cwd },
function(obj)
if obj.code ~= 0 then
return
end
vim.schedule(function()
local stdout = obj.stdout or ""
if stdout == "" then
return
end
local ok, env = pcall(vim.json.decode, stdout)
if not ok or type(env) ~= "table" then
return
end
for key, value in pairs(env) do
if value == vim.NIL or value == nil then
vim.env[key] = nil
else
if type(value) ~= "string" then
value = tostring(value)
end
vim.env[key] = value
end
end
notify("direnv environment unloaded", vim.log.levels.DEBUG)
end)
end
)
end
--- Initialize direnv for current directory
--- @param path string Path to .envrc file
M._init = function(path)
@ -421,6 +465,7 @@ end
M.check_direnv = function()
local on_exit = function(status, path)
if status == nil or path == nil then
M._unload()
return
end