From 84abecb6989bbea1ede39e5ae91338525e8bd0ff Mon Sep 17 00:00:00 2001 From: psychhim Date: Sun, 12 Oct 2025 21:06:13 +0530 Subject: [PATCH] Add: :UpdateKickestEnd command to update Neovim config from origin/master --- init.lua | 3 +++ lua/update_kickestend.lua | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 lua/update_kickestend.lua diff --git a/init.lua b/init.lua index 88c6cd8..539e0b4 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,9 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' +-- :UpdateKickestEnd command to safely update KickestEnd.nvim config from origin/master +require 'update_kickestend' + -- Load yank notification with line counts require 'yank_notification' diff --git a/lua/update_kickestend.lua b/lua/update_kickestend.lua new file mode 100644 index 0000000..145059b --- /dev/null +++ b/lua/update_kickestend.lua @@ -0,0 +1,45 @@ +-- ~/.config/nvim/lua/update_kickestend.lua +-- Command: :UpdateKickestEnd +-- Safely updates your KickestEnd.nvim config to the latest commit on origin/master + +vim.api.nvim_create_user_command('UpdateKickestEnd', function() + local config_path = vim.fn.expand '~/.config/nvim' + + -- Ensure this is a git repo + if vim.fn.isdirectory(config_path .. '/.git') == 0 then + vim.notify('Not a git repository: ' .. config_path, vim.log.levels.ERROR) + return + end + + -- Check for local modifications + local status = vim.fn.systemlist { 'git', '-C', config_path, 'status', '--porcelain' } + local dirty = #status > 0 + + if dirty then + local answer = vim.fn.input 'Local changes detected! Overwrite them and lose all changes? (y/N): ' + if answer:lower() ~= 'y' then + vim.notify('Update cancelled to preserve your modifications.', vim.log.levels.WARN) + return + end + + vim.notify('Discarding local modifications...', vim.log.levels.WARN) + vim.fn.system { 'git', '-C', config_path, 'reset', '--hard' } + end + + -- Fetch and update + vim.notify('Fetching latest changes from GitHub...', vim.log.levels.INFO) + local fetch = vim.fn.systemlist { 'git', '-C', config_path, 'fetch', '--all' } + if vim.v.shell_error ~= 0 then + vim.notify('Git fetch failed:\n' .. table.concat(fetch, '\n'), vim.log.levels.ERROR) + return + end + + vim.notify('Resetting to latest commit on origin/master...', vim.log.levels.INFO) + local reset = vim.fn.systemlist { 'git', '-C', config_path, 'reset', '--hard', 'origin/master' } + if vim.v.shell_error ~= 0 then + vim.notify('Git reset failed:\n' .. table.concat(reset, '\n'), vim.log.levels.ERROR) + return + end + + vim.notify('KickestEnd.nvim successfully updated to the latest commit on master!', vim.log.levels.INFO) +end, { desc = 'Safely update KickestEnd.nvim config from origin/master' })