mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 22:30:04 +08:00
feat(git): rewrite :Git branch
with lua
This commit is contained in:
parent
206c56db80
commit
9947755e66
@ -69,5 +69,71 @@ end
|
|||||||
function M.detect()
|
function M.detect()
|
||||||
update_branch_name(vim.fn.getcwd(), true)
|
update_branch_name(vim.fn.getcwd(), true)
|
||||||
end
|
end
|
||||||
|
local branch_jobid = -1
|
||||||
|
local stderr_data = {}
|
||||||
|
|
||||||
|
local function on_stdout(id, data)
|
||||||
|
if id ~= branch_jobid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for _, line in pairs(data) do
|
||||||
|
nt.notify_max_width = vim.fn.max({ vim.fn.strwidth(line) + 5, nt.notify_max_width })
|
||||||
|
nt.notify(line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_stderr(id, data)
|
||||||
|
if id ~= branch_jobid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for _, line in pairs(data) do
|
||||||
|
table.insert(stderr_data, line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_exit(id, code, single)
|
||||||
|
log.debug('branch exit code:' .. code .. ' single:' .. single)
|
||||||
|
if id ~= branch_jobid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if code == 0 and single == 0 then
|
||||||
|
for _, line in ipairs(stderr_data) do
|
||||||
|
nt.notify(line)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for _, line in ipairs(stderr_data) do
|
||||||
|
nt.notify(line, 'WarningMsg')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
branch_jobid = -1
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.run(argv)
|
||||||
|
if branch_jobid ~= -1 then
|
||||||
|
nt.notify('previous branch command is not finished')
|
||||||
|
end
|
||||||
|
|
||||||
|
nt.notify_max_width = vim.fn.float2nr(vim.o.columns * 0.3)
|
||||||
|
|
||||||
|
stderr_data = {}
|
||||||
|
|
||||||
|
local cmd = { 'git', 'branch' }
|
||||||
|
|
||||||
|
if argv then
|
||||||
|
for _, v in ipairs(argv) do
|
||||||
|
table.insert(cmd, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
log.debug(vim.inspect(cmd))
|
||||||
|
branch_jobid = job.start(cmd, {
|
||||||
|
on_stdout = on_stdout,
|
||||||
|
on_stderr = on_stderr,
|
||||||
|
on_exit = on_exit,
|
||||||
|
})
|
||||||
|
|
||||||
|
if branch_jobid == -1 then
|
||||||
|
nt.notify('`git` is not executable', 'WarningMsg')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user