summaryrefslogtreecommitdiff
path: root/lua/plugin-loader.lua
blob: 5921e9f1aec379242e375cd5e6652ce47f44e150 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local plugin_loader = {}

function plugin_loader:init(opts)
  opts = opts or {}

  local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack"
  local compile_path = opts.compile_path or vim.fn.stdpath "config" .. "/plugin/packer_compile.lua"

  if vim.fn.empty(vim.fn.glob(package_root)) > 0 then
    vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", package_root }
    vim.cmd "packadd packer.nvim"
  end

  local packer_ok, packer = pcall(require, "packer")
  if not packer_ok then
    return
  end

  packer.init {
    package_root = package_root,
    compile_path = compile_path,
    git = { clone_timeout = 300 },
    display = {
      open_fn = function()
        return require("packer.util").float { border = "rounded" }
      end,
    },
  }

  self.packer = packer
  return self
end

function plugin_loader:load(configurations)
  return self.packer.startup(function(use)
    for _, plugins in ipairs(configurations) do
      for _, plugin in ipairs(plugins) do
        use(plugin)
      end
    end
  end)
end

return plugin_loader