Use lua on_exit callback
This commit is contained in:
@@ -80,13 +80,11 @@ local function project_root_dir()
|
|||||||
return fn.system('cd ' .. fn.expand('%:p:h') .. ' && git rev-parse --show-toplevel 2> /dev/null')
|
return fn.system('cd ' .. fn.expand('%:p:h') .. ' && git rev-parse --show-toplevel 2> /dev/null')
|
||||||
end
|
end
|
||||||
|
|
||||||
execute([[
|
function on_exit(job_id, code, event)
|
||||||
function! s:OnExit(job_id, code, event) dict
|
if code == 0 then
|
||||||
if a:code == 0
|
api.nvim_command("bd!")
|
||||||
bd!
|
end
|
||||||
endif
|
end
|
||||||
endfunction
|
|
||||||
]])
|
|
||||||
|
|
||||||
local function exec_lazygit_command()
|
local function exec_lazygit_command()
|
||||||
local current_dir = fn.getcwd()
|
local current_dir = fn.getcwd()
|
||||||
@@ -95,7 +93,7 @@ local function exec_lazygit_command()
|
|||||||
local cmd = "lazygit " .. "-p " .. root_dir
|
local cmd = "lazygit " .. "-p " .. root_dir
|
||||||
-- ensure that the buffer is closed on exit
|
-- ensure that the buffer is closed on exit
|
||||||
execute([[
|
execute([[
|
||||||
call termopen('%s', {'on_exit': function('s:OnExit')})
|
call termopen('%s', {'on_exit': {job_id, code, event-> luaeval("require('lazygit').on_exit(" . job_id . "," . code . "," . event . ")")}})
|
||||||
]], cmd)
|
]], cmd)
|
||||||
execute("startinsert")
|
execute("startinsert")
|
||||||
end
|
end
|
||||||
@@ -119,4 +117,5 @@ end
|
|||||||
return {
|
return {
|
||||||
setup = setup,
|
setup = setup,
|
||||||
lazygit = lazygit,
|
lazygit = lazygit,
|
||||||
|
on_exit = on_exit,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user