From 1bcceaa3a8bc6bb6124494f1895891bf729ba890 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sat, 18 Jul 2020 01:18:14 -0600 Subject: [PATCH 1/3] Change file_buffer to be listed --- lua/lazygit.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index bd191de..1972e12 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -100,9 +100,9 @@ local function open_floating_window() vim.cmd 'set winhl=Normal:Floating' - -- create a unlisted scratch buffer - local file_buffer = api.nvim_create_buf(false, true) - -- create file window + -- create a listed scratch buffer + local file_buffer = api.nvim_create_buf(true, true) + -- 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' From 8c8698428da01f92c82bc3f3b651372a456a0f4a Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sat, 18 Jul 2020 01:19:11 -0600 Subject: [PATCH 2/3] Remove lua execute function which is no longer needed --- lua/lazygit.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 1972e12..eb2ed8c 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -2,11 +2,6 @@ vim = vim local api = vim.api local fn = vim.fn -local function execute(cmd, ...) - cmd = cmd:format(...) - vim.cmd(cmd) -end - local function trim(str) return str:gsub("^%s+", ""):gsub("%s+$", "") end From 485ca36e87c18f0c0a17fa0e487ee103360276a0 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sat, 18 Jul 2020 01:24:10 -0600 Subject: [PATCH 3/3] Add documentation and add LazyGitFilter entry point --- lua/lazygit.lua | 12 +++++++++--- plugin/lazygit.vim | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index eb2ed8c..8d64835 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -2,14 +2,17 @@ vim = vim local api = vim.api local fn = vim.fn +--- Strip leading and lagging whitespace local function trim(str) return str:gsub("^%s+", ""):gsub("%s+$", "") end +--- Check if lazygit is available local function is_lazygit_available() return fn.executable("lazygit") == 1 end +--- Get project_root_dir for git repository local function project_root_dir() -- try file location first local gitdir = fn.system('cd "' .. fn.expand('%:p:h') .. '" && git rev-parse --show-toplevel') @@ -29,6 +32,7 @@ local function project_root_dir() return fn.getcwd(0, 0) 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 @@ -36,6 +40,7 @@ local function on_exit(job_id, code, event) end end +--- Call lazygit 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 @@ -45,6 +50,7 @@ local function exec_lazygit_command(cmd) vim.cmd "startinsert" end +--- open floating window with nice borders local function open_floating_window() local floating_window_scaling_factor = vim.g.lazygit_floating_window_scaling_factor @@ -110,6 +116,7 @@ local function open_floating_window() vim.cmd(cmd:format(file_buffer, border_buffer)) end +--- :LazyGit entry point local function lazygit(path) if is_lazygit_available() ~= true then print("Please install lazygit. Check documentation for more information") @@ -124,6 +131,7 @@ local function lazygit(path) end +--- :LazyGitFilter entry point local function lazygitfilter(path) if is_lazygit_available() ~= true then print("Please install lazygit. Check documentation for more information") @@ -137,6 +145,7 @@ local function lazygitfilter(path) exec_lazygit_command(cmd) end +--- :LazyGitConfig entry point local function lazygitconfig() local os = fn.substitute(fn.system('uname'), '\n', '', '') local config_file = "" @@ -165,10 +174,7 @@ local function lazygitconfig() end return { - setup = setup, lazygit = lazygit, lazygitfilter = lazygitfilter, lazygitconfig = lazygitconfig, - on_exit = on_exit, - on_buf_leave = on_buf_leave, } diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index 9353ef1..16d43e5 100644 --- a/plugin/lazygit.vim +++ b/plugin/lazygit.vim @@ -17,6 +17,8 @@ endif command! LazyGit lua require'lazygit'.lazygit() +command! LazyGitFilter lua require'lazygit'.lazygitfilter() + command! LazyGitConfig lua require'lazygit'.lazygitconfig() """"""""""""""""""""""""""""""""""""""""""""""""""""""