Merge pull request #16 from refractalize/direnv-export-json

use direnv export json for multiline env vars
This commit is contained in:
raf 2026-01-20 14:05:44 +03:00 committed by GitHub
commit 2238a611b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -224,32 +224,42 @@ M._init = function(path)
end end
vim.schedule(function() vim.schedule(function()
local env_commands = vim.split(obj.stdout, "\n") local ok, env = pcall(vim.json.decode, obj.stdout)
if #env_commands > 0 then
for _, cmd in ipairs(env_commands) do
if cmd ~= "" then
pcall(function()
vim.cmd(cmd)
end)
end
end
if not silent then if not ok or type(env) ~= "table" then
notify( notify(
"direnv environment loaded successfully", "Failed to parse direnv JSON output",
vim.log.levels.INFO vim.log.levels.ERROR
) )
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
vim.api.nvim_exec_autocmds( end
"User",
{ pattern = "DirenvLoaded", modeline = false } if not silent then
notify(
"direnv environment loaded successfully",
vim.log.levels.INFO
) )
end end
vim.api.nvim_exec_autocmds(
"User",
{ pattern = "DirenvLoaded", modeline = false }
)
end) end)
end end
vim.system( vim.system(
{ M.config.bin, "export", "vim" }, { M.config.bin, "export", "json" },
{ text = true, cwd = cwd }, { text = true, cwd = cwd },
on_exit on_exit
) )