feat: improved update command

now resets with --force if invoked with bang. an arg can be given to
switch to that branch before pulling.
This commit is contained in:
əlemi 2022-08-19 05:23:12 +02:00
parent 51139ded5c
commit c8a503374a
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -137,17 +137,28 @@ function HL()
local id = vim.fn.synID(vim.fn.line('.'), vim.fn.col('.'), 1) local id = vim.fn.synID(vim.fn.line('.'), vim.fn.col('.'), 1)
local id_trans = vim.fn.synIDtrans(id) local id_trans = vim.fn.synIDtrans(id)
local name = vim.fn.synIDattr(id_trans, 'name') local name = vim.fn.synIDattr(id_trans, 'name')
print(id) print(string.format("Highlight #%d -> %s", id, id_trans))
print(id_trans)
print(name)
P(name) P(name)
end 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( vim.api.nvim_create_user_command(
'UpdateConfig', 'UpdateConfig',
function(args) function(args)
local stdout = vim.fn.system(string.format("git -C %s pull", vim.fn.stdpath('config'))) local cfg_path = vim.fn.stdpath('config')
print(stdout:sub(0, #stdout-1)) -- strip tailing newline 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, end,
{} {bang=true, nargs='?'}
) )