aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/nvim/lua/config/update.lua
diff options
context:
space:
mode:
Diffstat (limited to 'dot_config/nvim/lua/config/update.lua')
-rw-r--r--dot_config/nvim/lua/config/update.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/dot_config/nvim/lua/config/update.lua b/dot_config/nvim/lua/config/update.lua
new file mode 100644
index 0000000..72cb566
--- /dev/null
+++ b/dot_config/nvim/lua/config/update.lua
@@ -0,0 +1,47 @@
+-- Headless update orchestrator. Invoked from the justfile via:
+-- nvim --headless +'lua require("config.update").run()'
+--
+-- Cleans orphan plugins, applies plugin updates without prompting, then
+-- runs :MasonToolsUpdateSync (blocking variant intended for headless use).
+
+local M = {}
+
+local function say(msg)
+ io.stdout:write(msg .. "\n")
+ io.stdout:flush()
+end
+
+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
+ say(
+ ("[pack] removing %d orphan(s): %s"):format(
+ #orphans,
+ table.concat(orphans, ", ")
+ )
+ )
+ vim.pack.del(orphans)
+ end
+
+ say("[pack] updating plugins…")
+ vim.pack.update(nil, { force = true })
+
+ say("[mason] updating tools…")
+ vim.cmd("MasonToolsUpdateSync")
+
+ vim.cmd("qa!")
+end
+
+return M