From e779607c5fc7a23d6356fa04f5a4d42edfee4a0d Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 10 Sep 2023 15:40:52 -0700 Subject: [PATCH] [neovim] Add .vim in a top level of a git repo to runtimepath if it exists --- config/nvim/init.lua | 54 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 965a1ad..c93a4c1 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -1,12 +1,60 @@ -- Eryn Wells +require "os" + +function gitTopLevelDirectory() + local handle = io.popen("git rev-parse --show-toplevel") + local gitRepoTopLevelDirectoryPath = vim.fn.trim(handle:read("*a")) + handle:close() + return gitRepoTopLevelDirectoryPath +end + +local function _addPathToRuntimePath(path, options) + if string.len(path) == 0 then + return + end + + if vim.fn.isdirectory(path) == 1 then + if options.prepend then + vim.opt.runtimepath:prepend(path) + else + vim.opt.runtimepath:append(path) + end + end +end + +function addGitTopLevelDirectoryToRuntimePath() + local gitTopLevelPath = gitTopLevelDirectory() + if string.len(gitTopLevelPath) == 0 then + return + end + + local repoVimPath = gitTopLevelPath .. "/.vim" + if vim.fn.isdirectory(repoVimPath) == 1 then + vim.opt.runtimepath:prepend(repoVimPath) + end + local repoNvimPath = gitTopLevelPath .. "/.nvim" + if vim.fn.isdirectory(repoNvimPath) == 1 then + vim.opt.runtimepath:prepend(repoNvimPath) + end + + local repoVimAfterPath = gitTopLevelPath .. "/.nvim/after" + if vim.fn.isdirectory(repoVimAfterPath) == 1 then + vim.opt.runtimepath:append(repoVimAfterPath) + end + local repoNvimAfterPath = gitTopLevelPath .. "/.vim/after" + if vim.fn.isdirectory(repoNvimAfterPath) == 1 then + vim.opt.runtimepath:append(repoNvimAfterPath) + end +end + +addGitTopLevelDirectoryToRuntimePath() + vim.cmd [[ source ~/.vimrc.common - source ~/.vim/plugins.vim + source ~/.vim/plugins.vim ]] -require 'os' - require "configuration" require "colors" require "keys"