plugin-loader.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. local plugin_loader = {}
  2. local utils = require "utils"
  3. local Log = require "core.log"
  4. -- we need to reuse this outside of init()
  5. local compile_path = get_config_dir() .. "/plugin/packer_compiled.lua"
  6. function plugin_loader:init(opts)
  7. opts = opts or {}
  8. local install_path = opts.install_path or vim.fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim"
  9. local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack"
  10. if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  11. vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
  12. vim.cmd "packadd packer.nvim"
  13. end
  14. local packer_ok, packer = pcall(require, "packer")
  15. if not packer_ok then
  16. return
  17. end
  18. packer.init {
  19. package_root = package_root,
  20. compile_path = compile_path,
  21. git = { clone_timeout = 300 },
  22. display = {
  23. open_fn = function()
  24. return require("packer.util").float { border = "rounded" }
  25. end,
  26. },
  27. }
  28. self.packer = packer
  29. return self
  30. end
  31. function plugin_loader:cache_clear()
  32. if vim.fn.delete(compile_path) == 0 then
  33. Log:debug "deleted packer_compiled.lua"
  34. end
  35. end
  36. function plugin_loader:cache_reset()
  37. self.cache_clear()
  38. require("packer").compile()
  39. if utils.is_file(compile_path) then
  40. Log:debug "generated packer_compiled.lua"
  41. end
  42. end
  43. function plugin_loader:load(configurations)
  44. return self.packer.startup(function(use)
  45. for _, plugins in ipairs(configurations) do
  46. for _, plugin in ipairs(plugins) do
  47. use(plugin)
  48. end
  49. end
  50. end)
  51. end
  52. return plugin_loader