summaryrefslogtreecommitdiff
path: root/lua/plugin-loader.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/plugin-loader.lua')
-rw-r--r--lua/plugin-loader.lua43
1 files changed, 30 insertions, 13 deletions
diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua
index aa1e888d..c20dd21a 100644
--- a/lua/plugin-loader.lua
+++ b/lua/plugin-loader.lua
@@ -1,9 +1,18 @@
local plugin_loader = {}
-function plugin_loader:init()
- local install_path = "~/.local/share/lunarvim/site/pack/packer/start/packer.nvim"
+local utils = require "utils"
+local Log = require "core.log"
+-- we need to reuse this outside of init()
+local compile_path = get_config_dir() .. "/plugin/packer_compiled.lua"
+
+function plugin_loader:init(opts)
+ opts = opts or {}
+
+ local install_path = opts.install_path or vim.fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim"
+ local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack"
+
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
- vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path }
+ vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
vim.cmd "packadd packer.nvim"
end
@@ -12,15 +21,13 @@ function plugin_loader:init()
return
end
- local util = require "packer.util"
-
packer.init {
- package_root = util.join_paths "~/.local/share/lunarvim/site/pack/",
- compile_path = util.join_paths("~/.config/lvim", "plugin", "packer_compiled.lua"),
+ package_root = package_root,
+ compile_path = compile_path,
git = { clone_timeout = 300 },
display = {
open_fn = function()
- return util.float { border = "rounded" }
+ return require("packer.util").float { border = "rounded" }
end,
},
}
@@ -29,6 +36,20 @@ function plugin_loader:init()
return self
end
+function plugin_loader:cache_clear()
+ if vim.fn.delete(compile_path) == 0 then
+ Log:debug "deleted packer_compiled.lua"
+ end
+end
+
+function plugin_loader:cache_reset()
+ self.cache_clear()
+ require("packer").compile()
+ if utils.is_file(compile_path) then
+ Log:debug "generated packer_compiled.lua"
+ end
+end
+
function plugin_loader:load(configurations)
return self.packer.startup(function(use)
for _, plugins in ipairs(configurations) do
@@ -39,8 +60,4 @@ function plugin_loader:load(configurations)
end)
end
-return {
- init = function()
- return plugin_loader:init()
- end,
-}
+return plugin_loader