Something went wrong. Try again.
My own personal NeoVim configuration. Powered by vim.pack and lz.n
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101local interval_ms = 30 * 60 * 1000local interval_s = interval_ms / 1000local state_file = vim.fn.stdpath("state") .. "/config-update-last-check"local config_dir = vim.uv.fs_realpath(vim.fn.stdpath("config")) or vim.fn.stdpath("config")local running = false
local function last_check() local f = io.open(state_file, "r") if not f then return 0 end local n = tonumber(f:read("*l")) f:close() return n or 0end
local function mark_checked() vim.fn.mkdir(vim.fn.fnamemodify(state_file, ":h"), "p") local f = io.open(state_file, "w") if f then f:write(tostring(os.time())) f:close() endend
local function notify() local msg = "---------- notice ----------\nconfig update! restart now\n--------------" pcall(function() require("lz.n").trigger_load("fidget.nvim") end) local ok = pcall(function() require("fidget").notify(msg, vim.log.levels.ERROR, { annote = "", ttl = 600 }) end) if not ok then vim.notify(msg, vim.log.levels.ERROR) endend
local function git(args, cb) local cmd = { "git", "-C", config_dir } vim.list_extend(cmd, args) local env = { GIT_TERMINAL_PROMPT = "0" } if not vim.env.GIT_SSH_COMMAND then env.GIT_SSH_COMMAND = "ssh -o BatchMode=yes -o ConnectTimeout=10" end local ok = pcall(vim.system, cmd, { text = true, env = env, timeout = 60000 }, function(res) vim.schedule(function() cb(res) end) end) if not ok then running = false endend
local function finish() running = falseend
local function check() if running or vim.fn.executable("git") ~= 1 then return end running = true mark_checked() git({ "fetch", "--quiet" }, function(fetched) if fetched.code ~= 0 then return finish() end git({ "rev-list", "--count", "HEAD..@{u}" }, function(counted) if counted.code ~= 0 or (tonumber(vim.trim(counted.stdout or "")) or 0) == 0 then return finish() end git({ "merge", "--ff-only", "--quiet", "@{u}" }, function(merged) finish() if merged.code == 0 then notify() end end) end) end)end
vim.api.nvim_create_autocmd("UIEnter", { once = true, callback = function() vim.schedule(function() if os.time() - last_check() >= interval_s then check() end end) end,})
local timer = vim.uv.new_timer()if timer then timer:start(interval_ms, interval_ms, function() vim.schedule(check) end)end