diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 034337d..0acc9eb 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -1,3 +1,4 @@ +vim = vim local api = vim.api local fn = vim.fn @@ -30,14 +31,19 @@ local function project_root_dir() return fn.getcwd(0, 0) end +local function on_exit(job_id, code, event) + if code == 0 then + -- delete terminal buffer + vim.cmd("silent! bdelete!") + end +end + local function exec_lazygit_command(cmd) if ( fn.has("win64") == 0 and fn.has("win32") == 0 and fn.has("win16") == 0 ) then cmd = "GIT_EDITOR=nvim " .. cmd end -- ensure that the buffer is closed on exit - execute([[ - call termopen('%s', {'on_exit': {job_id, code, event-> luaeval("require('lazygit').on_exit(" . job_id . "," . code . "," . event . ")")}}) - ]], cmd) + vim.fn.termopen(cmd, { on_exit = on_exit }) vim.cmd "startinsert" end @@ -105,13 +111,6 @@ local function open_floating_window() vim.cmd(cmd:format(file_buffer, border_buffer)) end -local function on_exit(job_id, code, event) - if code == 0 then - -- delete terminal buffer - vim.cmd("silent! bdelete!") - end -end - local function lazygit(path) if is_lazygit_available() ~= true then print("Please install lazygit. Check documentation for more information")