From c8a503374a725adbb54a05280bf53623a5c32fac Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 19 Aug 2022 05:23:12 +0200 Subject: [PATCH] feat: improved update command now resets with --force if invoked with bang. an arg can be given to switch to that branch before pulling. --- init.lua | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/init.lua b/init.lua index 9ab3420..50df8ba 100644 --- a/init.lua +++ b/init.lua @@ -137,17 +137,28 @@ function HL() local id = vim.fn.synID(vim.fn.line('.'), vim.fn.col('.'), 1) local id_trans = vim.fn.synIDtrans(id) local name = vim.fn.synIDattr(id_trans, 'name') - print(id) - print(id_trans) - print(name) + print(string.format("Highlight #%d -> %s", id, id_trans)) P(name) end +local function shell_cmd(str) + local stdout = vim.fn.system(str) + local output, _ = stdout:sub(0, #stdout-1):gsub("\t", " ") + print(output) + return vim.v.shell_error == 0 +end + vim.api.nvim_create_user_command( 'UpdateConfig', function(args) - local stdout = vim.fn.system(string.format("git -C %s pull", vim.fn.stdpath('config'))) - print(stdout:sub(0, #stdout-1)) -- strip tailing newline + local cfg_path = vim.fn.stdpath('config') + if args.bang then + if not shell_cmd(string.format("git -C %s reset --hard", cfg_path)) then return end + end + if #args.args > 0 then + if not shell_cmd(string.format("git -C %s checkout %s", cfg_path, args.args)) then return end + end + shell_cmd(string.format("git -C %s pull", cfg_path)) end, - {} + {bang=true, nargs='?'} )