2022-04-28 06:56:17 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- - Direnv + Vimrc extensions -
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.get_local_vimrc()
|
2022-04-28 13:53:54 +00:00
|
|
|
local extra_vimrc_location = vim.env.DIRENV_EXTRA_VIMRC
|
2022-04-28 06:56:17 +00:00
|
|
|
|
2022-04-28 13:53:54 +00:00
|
|
|
return extra_vimrc_location
|
2022-04-28 06:56:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.open_local_vimrc()
|
2022-04-28 13:53:54 +00:00
|
|
|
local local_vimrc = M.get_local_vimrc()
|
2022-04-28 06:56:17 +00:00
|
|
|
|
2022-04-28 13:53:54 +00:00
|
|
|
if local_vimrc == nil then
|
|
|
|
local_vimrc = vim.fn.input("Local vimrc filename: ", ".vimrc")
|
|
|
|
local save = vim.fn.input("Save to .envrc? [y/N]", "y")
|
|
|
|
if save == "y" then
|
|
|
|
local existing_envrc = vim.fn.readfile(".envrc")
|
|
|
|
local write = true
|
|
|
|
for line in existing_envrc do
|
|
|
|
if string.find(line, "export DIRENV_EXTRA_VIMRC") then
|
|
|
|
write = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if write then
|
|
|
|
vim.fn.writefile({ "export DIRENV_EXTRA_VIMRC=" .. local_vimrc }, ".envrc", "a")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-04-28 06:56:17 +00:00
|
|
|
|
2022-04-28 13:53:54 +00:00
|
|
|
vim.cmd("edit " .. local_vimrc)
|
2022-04-28 06:56:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|