From 5afca55c6988cacbeb633fad8cbd2468662b1402 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sun, 5 Apr 2020 14:17:43 -0600 Subject: [PATCH] Use bd! on exit code == 0 --- lua/lazygit.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 699d445..c2b7607 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -60,7 +60,8 @@ function open_floating_window() local window = api.nvim_open_win(buffer, true, opts) api.nvim_command('set winhl=Normal:Floating') -- use autocommand to ensure that the border_buffer closes at the same time as the main buffer - api.nvim_command('au BufWipeout exe "silent bwipeout!"' .. border_buffer) + api.nvim_command('au BufWipeout execute "silent bwipeout!"' .. border_buffer) + -- api.nvim_command('au TermOpen * startinsert!') return window end @@ -73,6 +74,14 @@ local function execute(cmd, ...) vim.api.nvim_command(cmd) end +execute([[ +function! s:OnExit(job_id, code, event) dict + if a:code == 0 + bd! + endif +endfunction +]]) + local function exec_lazygit_command() local current_dir = fn.getcwd() -- TODO: ensure that it is a valid git directory @@ -80,7 +89,7 @@ local function exec_lazygit_command() local cmd = "lazygit " .. "-p " .. root_dir -- ensure that the buffer is closed on exit execute([[ - call termopen('%s', {'on_exit': {-> execute(':q')}}) + call termopen('%s', {'on_exit': function('s:OnExit')}) ]], cmd) end