aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/nvim/lua/config/update.lua
blob: bc7ee3d66ac91dec96e5bcfa034418d3cf81dfeb (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
42
-- Update orchestrator. Invoked from the justfile via:
--   nvim +'lua require("config.update").run()'
--
-- Cleans orphan plugins, applies plugin updates without prompting, then
-- runs :MasonToolsUpdateSync. Run interactively (not --headless) so the
-- diff buffer that vim.pack.update opens is actually visible — that
-- buffer IS the changelog. Quit manually with :qa once reviewed.

local M = {}

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

function M.run()
  local orphans = orphan_names()
  if #orphans > 0 then
    print(
      ("[pack] removing %d orphan(s): %s"):format(
        #orphans,
        table.concat(orphans, ", ")
      )
    )
    vim.pack.del(orphans)
  end

  print("[pack] updating plugins…")
  vim.pack.update(nil, { force = true })

  print("[mason] updating tools…")
  vim.cmd("MasonToolsUpdateSync")
end

return M