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