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:
parent
51139ded5c
commit
c8a503374a
1 changed files with 17 additions and 6 deletions
23
init.lua
23
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='?'}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue