grace/dots

dotfiles/nix configs

git clone https://git.gae.moe/grace/dots

Grace Yoderhx and vcs changesddf0c79

main
2.6 KiB127 linesraw
1--
2-- Packed: a single file, somewhat compatible Packer replacement
3-- Written by grace
4--
5
6local function resolve_src(s)
7  if s:match("^https?://") then
8    return s
9  end
10  if s:match("^[%w%-]+/[%w%-_.]+$") then
11    return "https://github.com/" .. s
12  end
13  return s
14end
15
16local function normalize_plugin(p)
17  if type(p) == "string" then
18    return {
19      src = resolve_src(p),
20      name = p:match(".*/(.*)"),
21    }
22  end
23
24  if type(p[1]) == "string" then
25    p.src = resolve_src(p[1])
26    p[1] = nil
27  end
28
29  if p.src then
30    p.src = resolve_src(p.src)
31  end
32
33  if not p.name and p.as then
34    p.name = p.as
35  end
36
37  if not p.version then
38    if p.commit then
39      p.version = p.commit
40    elseif p.tag then
41      p.version = p.tag
42    elseif p.branch then
43      p.version = p.branch
44    end
45  end
46
47
48
49  local unsupported = {
50    'disable', 'installer', 'updater', 'after', 'rtp',
51    'opt', 'bufread', 'lock', 'run', 'requires', 'rocks', 'setup'
52  }
53
54  for _, field in ipairs(unsupported) do
55    if p[field] then
56      vim.notify("Packed does not support `" .. field .. "`: " .. (p.name or p.src), vim.log.levels.WARN)
57      vim.api.nvim_echo({ { "Press Enter to continue...", "MoreMsg" } }, false, {})
58      vim.fn.getchar()
59    end
60  end
61
62  if p.cmd or p.ft or p.keys or p.event or p.fn or p.cond or p.module or p.module_pattern then
63    vim.notify("Packed does not support lazy loading: " .. (p.name or p.src), vim.log.levels.WARN)
64    vim.api.nvim_echo({ { "Press Enter to continue...", "MoreMsg" } }, false, {})
65    vim.fn.getchar()
66  end
67
68
69
70  return p
71end
72
73local function setup_plugins(plugs)
74  local plugins = {}
75
76  if type(plugs) == "function" then
77    local function use(p)
78      table.insert(plugins, p)
79    end
80
81    plugs(use)
82  else
83    plugins = plugs
84  end
85  local specs = {}
86
87  for _, p in ipairs(plugins) do
88    p = normalize_plugin(p)
89
90    local spec = vim.deepcopy(p)
91    spec.config = nil
92
93    table.insert(specs, spec)
94  end
95
96  vim.pack.add(specs, { confirm = true, load = true })
97
98
99  for _, p in ipairs(plugins) do
100    if type(p) ~= "string" and p.config then
101      local ok = pcall(p.config)
102      if not ok then
103        vim.notify("Config failed: " .. (p.name or p.src), vim.log.levels.ERROR)
104        vim.api.nvim_echo({ { "Press Enter to continue...", "MoreMsg" } }, false, {})
105        vim.fn.getchar()
106      end
107    end
108  end
109
110
111  local unused = vim.iter(vim.pack.get())
112      :filter(function(p)
113        return not p.active
114      end)
115      :map(function(p)
116        return p.spec.name
117      end)
118      :totable()
119
120  vim.pack.del(unused)
121end
122
123
124local r = {}
125r.setup = setup_plugins
126
127return r