#60 small refactoring: update teardown cleanup process

This commit is contained in:
thefux
2022-09-06 15:34:26 +02:00
parent 9c73fd69a4
commit 061256662c
2 changed files with 13 additions and 3 deletions

View File

@@ -9,6 +9,8 @@ LAZYGIT_BUFFER = nil
LAZYGIT_LOADED = false
vim.g.lazygit_opened = 0
local prev_win = -1
local win = -1
local buffer = -1
--- on_exit callback function to delete the open buffer when lazygit exits in a neovim terminal
local function on_exit(job_id, code, event)
@@ -16,14 +18,20 @@ local function on_exit(job_id, code, event)
return
end
vim.cmd('silent! :q')
LAZYGIT_BUFFER = nil
LAZYGIT_LOADED = false
vim.g.lazygit_opened = 0
vim.cmd('silent! :checktime')
if vim.api.nvim_win_is_valid(prev_win) then
vim.api.nvim_win_close(win, true)
vim.api.nvim_set_current_win(prev_win)
prev_win = -1
if vim.api.nvim_buf_is_valid(buffer) and vim.api.nvim_buf_is_loaded(buffer) then
vim.api.nvim_buf_delete(buffer, { force = true })
end
buffer = -1
win = -1
end
end
@@ -47,7 +55,7 @@ local function lazygit(path)
prev_win = vim.api.nvim_get_current_win()
open_floating_window()
win, buffer = open_floating_window()
local cmd = 'lazygit'