aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/nvim/lua/config/pack.lua
blob: bdef8724997631e2bade02e51335cff13f9dc250 (plain) (blame)
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
-- User commands wrapping vim.pack for ergonomic update/clean/sync workflows.

local function orphans()
  return vim
    .iter(vim.pack.get())
    :filter(function(x)
      return not x.active
    end)
    :map(function(x)
      return x.spec.name
    end)
    :totable()
end

local function clean()
  local names = orphans()
  if #names == 0 then
    vim.notify("no orphan plugins", vim.log.levels.INFO)
    return
  end
  vim.pack.del(names)
end

local function update()
  vim.pack.update(nil, { force = true })
end

vim.api.nvim_create_user_command("PackClean", clean, {
  desc = "Remove plugins not declared in vim.pack.add()",
})

vim.api.nvim_create_user_command("PackUpdate", update, {
  desc = "Update all plugins without confirmation",
})

vim.api.nvim_create_user_command("PackSync", function()
  clean()
  update()
end, {
  desc = "Clean orphan plugins then update the rest",
})