mirror of
https://github.com/NotAShelf/direnv.nvim.git
synced 2025-02-05 16:43:26 +00:00
Use temporary file + source, instead of new line splitting
This commit is contained in:
parent
3e38d855c7
commit
76aa825d0d
1 changed files with 32 additions and 12 deletions
|
@ -128,16 +128,36 @@ M._init = function(path)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local cwd = vim.fs.dirname(path)
|
local cwd = vim.fs.dirname(path)
|
||||||
|
local temppath = vim.fn.tempname()
|
||||||
|
local tempfile = io.open(temppath, "w")
|
||||||
|
|
||||||
|
if not tempfile then
|
||||||
|
vim.notify("Couldn't create temporary file", vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local write_output = function(err, data)
|
||||||
|
if data then
|
||||||
|
tempfile:write(data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local on_exit = function(obj)
|
local on_exit = function(obj)
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.fn.execute(vim.fn.split(obj.stdout, "\n"))
|
if obj.code ~= 0 then
|
||||||
|
vim.notify("Direnv exited with an error", vim.log.levels.ERROR)
|
||||||
|
else
|
||||||
|
vim.cmd.source(temppath)
|
||||||
|
end
|
||||||
|
|
||||||
|
tempfile:close()
|
||||||
|
os.remove(temppath)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.system(
|
vim.system(
|
||||||
{ "direnv", "export", "vim" },
|
{ "direnv", "export", "vim" },
|
||||||
{ text = true, cwd = cwd },
|
{ cwd = cwd, stdout = write_output },
|
||||||
on_exit
|
on_exit
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -148,17 +168,17 @@ M.check_direnv = function()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Allowed
|
|
||||||
if status == 0 then
|
|
||||||
return M._init(path)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Blocked
|
|
||||||
if status == 2 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
|
-- Allowed
|
||||||
|
if status == 0 then
|
||||||
|
return M._init(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Blocked
|
||||||
|
if status == 2 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local choice =
|
local choice =
|
||||||
vim.fn.confirm(path .. " is blocked.", "&Allow\n&Block\n&Ignore", 3)
|
vim.fn.confirm(path .. " is blocked.", "&Allow\n&Block\n&Ignore", 3)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue