Add helpers for local vimrc

pull/2/head
Ensar Sarajčić 2022-04-28 08:56:17 +02:00
parent 6d7ed000ee
commit 93928177f1
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,35 @@
-------------------------------------------------------------------------------
-- - Direnv + Vimrc extensions -
-------------------------------------------------------------------------------
local M = {}
function M.get_local_vimrc()
local extra_vimrc_location = vim.env.DIRENV_EXTRA_VIMRC
return extra_vimrc_location
end
function M.open_local_vimrc()
local local_vimrc = M.get_local_vimrc()
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
vim.cmd("edit " .. local_vimrc)
end
return M

View File

@ -0,0 +1,5 @@
-------------------------------------------------------------------------------
-- - Local vimrc commands -
-------------------------------------------------------------------------------
vim.api.nvim_create_user_command("EditLocalVimrc", function(_) require"direnv_vimrc_local".open_local_vimrc() end, { nargs = 0 })