diff --git a/lua/lazygit.lua b/lua/lazygit.lua index bd191de..8d64835 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -2,19 +2,17 @@ vim = vim local api = vim.api local fn = vim.fn -local function execute(cmd, ...) - cmd = cmd:format(...) - vim.cmd(cmd) -end - +--- 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') @@ -34,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 @@ -41,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 @@ -50,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 @@ -100,9 +101,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' @@ -115,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") @@ -129,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") @@ -142,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 = "" @@ -170,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() """"""""""""""""""""""""""""""""""""""""""""""""""""""