mirror of
https://github.com/NotAShelf/direnv.nvim.git
synced 2026-02-24 12:23:23 +00:00
Merge pull request #16 from refractalize/direnv-export-json
use direnv export json for multiline env vars
This commit is contained in:
commit
2238a611b9
1 changed files with 27 additions and 17 deletions
|
|
@ -224,13 +224,24 @@ 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 not ok or type(env) ~= "table" then
|
||||||
if cmd ~= "" then
|
notify(
|
||||||
pcall(function()
|
"Failed to parse direnv JSON output",
|
||||||
vim.cmd(cmd)
|
vim.log.levels.ERROR
|
||||||
end)
|
)
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -244,12 +255,11 @@ M._init = function(path)
|
||||||
"User",
|
"User",
|
||||||
{ pattern = "DirenvLoaded", modeline = false }
|
{ pattern = "DirenvLoaded", modeline = false }
|
||||||
)
|
)
|
||||||
end
|
|
||||||
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
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue