diff options
| author | Sergio Mendez <[email protected]> | 2021-10-20 12:05:18 -0400 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-20 18:05:18 +0200 | 
| commit | 5cf8c07ee921f8dfed03415fe5b8322754ea8615 (patch) | |
| tree | 001447e6f312499686d8fd5d13e5d48a3c6a7647 /lua | |
| parent | 9be8ea6aab5f6f4618cdcdbeafd9eec6bc049d24 (diff) | |
fix(bootstrap): support for using default neovim config and data directories (#1777)
Co-authored-by: kylo252 <[email protected]>
Co-authored-by: James Walmsley <[email protected]>
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lvim/bootstrap.lua | 82 | ||||
| -rw-r--r-- | lua/lvim/core/dashboard.lua | 2 | 
2 files changed, 42 insertions, 42 deletions
| diff --git a/lua/lvim/bootstrap.lua b/lua/lvim/bootstrap.lua index b1ecdf1c..fbb362ce 100644 --- a/lua/lvim/bootstrap.lua +++ b/lua/lvim/bootstrap.lua @@ -3,11 +3,12 @@ local M = {}  package.loaded["lvim.utils.hooks"] = nil  local _, hooks = pcall(require, "lvim.utils.hooks") +local uv = vim.loop +local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/" +  ---Join path segments that were passed as input  ---@return string  function _G.join_paths(...) -  local uv = vim.loop -  local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/"    local result = table.concat({ ... }, path_sep)    return result  end @@ -18,7 +19,7 @@ function _G.get_runtime_dir()    local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR"    if not lvim_runtime_dir then      -- when nvim is used directly -    return vim.fn.stdpath "config" +    return vim.fn.stdpath "data"    end    return lvim_runtime_dir  end @@ -43,47 +44,24 @@ function _G.get_cache_dir()    return lvim_cache_dir  end ----Get the full path to the currently installed lunarvim repo ----@return string -local function get_install_path() -  local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR" -  if not lvim_runtime_dir then -    -- when nvim is used directly -    return vim.fn.stdpath "config" -  end -  return join_paths(lvim_runtime_dir, "lvim") -end - ----Get currently installed version of LunarVim ----@param type string can be "short" ----@return string -function _G.get_version(type) -  type = type or "" -  local lvim_full_ver = vim.fn.system("git -C " .. get_install_path() .. " describe --tags") - -  if string.match(lvim_full_ver, "%d") == nil then -    return nil -  end -  if type == "short" then -    return vim.fn.split(lvim_full_ver, "-")[1] -  else -    return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1) -  end -end -  ---Initialize the `&runtimepath` variables and prepare for startup  ---@return table -function M:init() +function M:init(base_dir)    self.runtime_dir = get_runtime_dir()    self.config_dir = get_config_dir()    self.cache_path = get_cache_dir() -  self.install_path = get_install_path() -    self.pack_dir = join_paths(self.runtime_dir, "site", "pack")    self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim")    self.packer_cache_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua") +  ---Get the full path to LunarVim's base directory +  ---@return string +  function _G.get_lvim_base_dir() +    return base_dir +  end +    if os.getenv "LUNARVIM_RUNTIME_DIR" then +    -- vim.opt.rtp:append(os.getenv "LUNARVIM_RUNTIME_DIR" .. path_sep .. "lvim")      vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site"))      vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site", "after"))      vim.opt.rtp:prepend(join_paths(self.runtime_dir, "site")) @@ -128,10 +106,10 @@ function M:update()    hooks.run_post_update()  end -local function git_cmd(subcmd) +local function git_cmd(subcmd, opts)    local Job = require "plenary.job"    local Log = require "lvim.core.log" -  local args = { "-C", get_install_path() } +  local args = { "-C", opts.cwd }    vim.list_extend(args, subcmd)    local stderr = {} @@ -139,7 +117,7 @@ local function git_cmd(subcmd)      :new({        command = "git",        args = args, -      cwd = get_install_path(), +      cwd = opts.cwd,        on_stderr = function(_, data)          table.insert(stderr, data)        end, @@ -154,7 +132,7 @@ local function git_cmd(subcmd)      Log:debug(stdout)    end -  return ret +  return ret, stdout  end  ---pulls the latest changes from github @@ -165,22 +143,25 @@ function M:update_repo()      diff = { "diff", "--quiet", "@{upstream}" },      merge = { "merge", "--ff-only", "--progress" },    } +  local opts = { +    cwd = get_lvim_base_dir(), +  }    Log:info "Checking for updates" -  local ret = git_cmd(sub_commands.fetch) +  local ret = git_cmd(sub_commands.fetch, opts)    if ret ~= 0 then      Log:error "Update failed! Check the log for further information"      return    end -  ret = git_cmd(sub_commands.diff) +  ret = git_cmd(sub_commands.diff, opts)    if ret == 0 then      Log:info "LunarVim is already up-to-date"      return    end -  ret = git_cmd(sub_commands.merge) +  ret = git_cmd(sub_commands.merge, opts)    if ret ~= 0 then      Log:error "Update failed! Please pull the changes manually instead." @@ -188,4 +169,23 @@ function M:update_repo()    end  end +---Get currently installed version of LunarVim +---@param type string can be "short" +---@return string +function M:get_version(type) +  type = type or "" +  local opts = { cwd = get_lvim_base_dir() } +  local status_ok, results = git_cmd({ "describe", "--tags" }, opts) +  local lvim_full_ver = results[1] or "" + +  if not status_ok or string.match(lvim_full_ver, "%d") == nil then +    return nil +  end +  if type == "short" then +    return vim.fn.split(lvim_full_ver, "-")[1] +  else +    return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1) +  end +end +  return M diff --git a/lua/lvim/core/dashboard.lua b/lua/lvim/core/dashboard.lua index 38d9d226..108ed0d2 100644 --- a/lua/lvim/core/dashboard.lua +++ b/lua/lvim/core/dashboard.lua @@ -70,7 +70,7 @@ M.setup = function()    vim.g.dashboard_session_directory = lvim.builtin.dashboard.session_directory    local lvim_site = "lunarvim.org" -  local lvim_version = get_version "short" +  local lvim_version = require("lvim.bootstrap"):get_version "short"    local num_plugins_loaded = #vim.fn.globpath(get_runtime_dir() .. "/site/pack/packer/start", "*", 0, 1)    local footer = { | 
