plugin-loader.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. local plugin_loader = {}
  2. function plugin_loader:init(opts)
  3. opts = opts or {}
  4. local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack"
  5. local compile_path = opts.compile_path or vim.fn.stdpath "config" .. "/plugin/packer_compile.lua"
  6. if vim.fn.empty(vim.fn.glob(package_root)) > 0 then
  7. vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", package_root }
  8. vim.cmd "packadd packer.nvim"
  9. end
  10. local packer_ok, packer = pcall(require, "packer")
  11. if not packer_ok then
  12. return
  13. end
  14. packer.init {
  15. package_root = package_root,
  16. compile_path = compile_path,
  17. git = { clone_timeout = 300 },
  18. display = {
  19. open_fn = function()
  20. return require("packer.util").float { border = "rounded" }
  21. end,
  22. },
  23. }
  24. self.packer = packer
  25. return self
  26. end
  27. function plugin_loader:load(configurations)
  28. return self.packer.startup(function(use)
  29. for _, plugins in ipairs(configurations) do
  30. for _, plugin in ipairs(plugins) do
  31. use(plugin)
  32. end
  33. end
  34. end)
  35. end
  36. return plugin_loader