From e3aac4d907846020db82d41a75babbe0b19b8393 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sat, 18 Jul 2020 17:03:06 -0600 Subject: [PATCH 1/2] Make buffer persistent --- lua/lazygit.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index d26fe17..51383ff 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -3,6 +3,7 @@ local api = vim.api local fn = vim.fn FILE_BUFFER = nil +LAZYGIT_LOADED = false --- Strip leading and lagging whitespace local function trim(str) @@ -40,6 +41,7 @@ local function on_exit(job_id, code, event) -- delete terminal buffer vim.cmd("silent! bdelete!") FILE_BUFFER = nil + LAZYGIT_LOADED = false end end @@ -53,9 +55,11 @@ end --- Call lazygit local function exec_lazygit_command(cmd) - cmd = git_editor_prefix(cmd) - -- ensure that the buffer is closed on exit - vim.fn.termopen(cmd, { on_exit = on_exit }) + if LAZYGIT_LOADED == false then + cmd = git_editor_prefix(cmd) + -- ensure that the buffer is closed on exit + vim.fn.termopen(cmd, { on_exit = on_exit }) + end vim.cmd "startinsert" end @@ -113,18 +117,23 @@ local function open_floating_window() -- create a unlisted scratch buffer if FILE_BUFFER == nil then FILE_BUFFER = api.nvim_create_buf(false, true) + else + LAZYGIT_LOADED = true end -- create file window, enter the window, and use the options defined in opts local file_window = api.nvim_open_win(FILE_BUFFER, true, opts) vim.bo[FILE_BUFFER].filetype = 'lazygit' + vim.cmd('setlocal bufhidden=hide') vim.cmd('setlocal nocursorcolumn') vim.cmd('set winblend=' .. vim.g.lazygit_floating_window_winblend) -- use autocommand to ensure that the border_buffer closes at the same time as the main buffer - local cmd = [[autocmd WinLeave silent! execute 'silent bdelete! %s %s']] - vim.cmd(cmd:format(FILE_BUFFER, border_buffer)) + local cmd = [[autocmd WinLeave silent! execute 'hide']] + vim.cmd(cmd) + local cmd = [[autocmd WinLeave silent! execute 'silent bdelete! %s']] + vim.cmd(cmd:format(border_buffer)) end --- :LazyGit entry point From 259c208771ef9b171d1fc83209d788ccc0f97146 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sat, 18 Jul 2020 17:12:48 -0600 Subject: [PATCH 2/2] Fix startify issue --- lua/lazygit.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 51383ff..466446c 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -2,7 +2,7 @@ vim = vim local api = vim.api local fn = vim.fn -FILE_BUFFER = nil +LAZYGIT_BUFFER = nil LAZYGIT_LOADED = false --- Strip leading and lagging whitespace @@ -38,9 +38,9 @@ end --- on_exit callback function to delete the open buffer when lazygit exits in a neovim terminal local function on_exit(job_id, code, event) if code == 0 then - -- delete terminal buffer - vim.cmd("silent! bdelete!") - FILE_BUFFER = nil + -- Close the window where the LAZYGIT_BUFFER is + vim.cmd("silent! :q") + LAZYGIT_BUFFER = nil LAZYGIT_LOADED = false end end @@ -115,15 +115,15 @@ local function open_floating_window() vim.cmd 'set winhl=Normal:Floating' -- create a unlisted scratch buffer - if FILE_BUFFER == nil then - FILE_BUFFER = api.nvim_create_buf(false, true) + if LAZYGIT_BUFFER == nil then + LAZYGIT_BUFFER = api.nvim_create_buf(false, true) else LAZYGIT_LOADED = true end -- create file window, enter the window, and use the options defined in opts - local file_window = api.nvim_open_win(FILE_BUFFER, true, opts) + local file_window = api.nvim_open_win(LAZYGIT_BUFFER, true, opts) - vim.bo[FILE_BUFFER].filetype = 'lazygit' + vim.bo[LAZYGIT_BUFFER].filetype = 'lazygit' vim.cmd('setlocal bufhidden=hide') vim.cmd('setlocal nocursorcolumn')