diff --git a/symlinks/config/nvim/lua/direnv_vimrc_local.lua b/symlinks/config/nvim/lua/direnv_vimrc_local.lua new file mode 100644 index 0000000..c62f499 --- /dev/null +++ b/symlinks/config/nvim/lua/direnv_vimrc_local.lua @@ -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 diff --git a/symlinks/config/nvim/plugin/local_vimrc.lua b/symlinks/config/nvim/plugin/local_vimrc.lua new file mode 100644 index 0000000..9124c62 --- /dev/null +++ b/symlinks/config/nvim/plugin/local_vimrc.lua @@ -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 })