plugin-loader.lua 1.2 KB

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