Merge pull request #15 from kdheepak/kd/fix-floating-window-persistence
This commit is contained in:
@@ -2,19 +2,17 @@ vim = vim
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
|
||||||
local function execute(cmd, ...)
|
--- Strip leading and lagging whitespace
|
||||||
cmd = cmd:format(...)
|
|
||||||
vim.cmd(cmd)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function trim(str)
|
local function trim(str)
|
||||||
return str:gsub("^%s+", ""):gsub("%s+$", "")
|
return str:gsub("^%s+", ""):gsub("%s+$", "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check if lazygit is available
|
||||||
local function is_lazygit_available()
|
local function is_lazygit_available()
|
||||||
return fn.executable("lazygit") == 1
|
return fn.executable("lazygit") == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get project_root_dir for git repository
|
||||||
local function project_root_dir()
|
local function project_root_dir()
|
||||||
-- try file location first
|
-- try file location first
|
||||||
local gitdir = fn.system('cd "' .. fn.expand('%:p:h') .. '" && git rev-parse --show-toplevel')
|
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)
|
return fn.getcwd(0, 0)
|
||||||
end
|
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)
|
local function on_exit(job_id, code, event)
|
||||||
if code == 0 then
|
if code == 0 then
|
||||||
-- delete terminal buffer
|
-- delete terminal buffer
|
||||||
@@ -41,6 +40,7 @@ local function on_exit(job_id, code, event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Call lazygit
|
||||||
local function exec_lazygit_command(cmd)
|
local function exec_lazygit_command(cmd)
|
||||||
if ( fn.has("win64") == 0 and fn.has("win32") == 0 and fn.has("win16") == 0 ) then
|
if ( fn.has("win64") == 0 and fn.has("win32") == 0 and fn.has("win16") == 0 ) then
|
||||||
cmd = "GIT_EDITOR=nvim " .. cmd
|
cmd = "GIT_EDITOR=nvim " .. cmd
|
||||||
@@ -50,6 +50,7 @@ local function exec_lazygit_command(cmd)
|
|||||||
vim.cmd "startinsert"
|
vim.cmd "startinsert"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- open floating window with nice borders
|
||||||
local function open_floating_window()
|
local function open_floating_window()
|
||||||
local floating_window_scaling_factor = vim.g.lazygit_floating_window_scaling_factor
|
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'
|
vim.cmd 'set winhl=Normal:Floating'
|
||||||
|
|
||||||
-- create a unlisted scratch buffer
|
-- create a listed scratch buffer
|
||||||
local file_buffer = api.nvim_create_buf(false, true)
|
local file_buffer = api.nvim_create_buf(true, true)
|
||||||
-- create file window
|
-- 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(file_buffer, true, opts)
|
||||||
|
|
||||||
vim.bo[file_buffer].filetype = 'lazygit'
|
vim.bo[file_buffer].filetype = 'lazygit'
|
||||||
@@ -115,6 +116,7 @@ local function open_floating_window()
|
|||||||
vim.cmd(cmd:format(file_buffer, border_buffer))
|
vim.cmd(cmd:format(file_buffer, border_buffer))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- :LazyGit entry point
|
||||||
local function lazygit(path)
|
local function lazygit(path)
|
||||||
if is_lazygit_available() ~= true then
|
if is_lazygit_available() ~= true then
|
||||||
print("Please install lazygit. Check documentation for more information")
|
print("Please install lazygit. Check documentation for more information")
|
||||||
@@ -129,6 +131,7 @@ local function lazygit(path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- :LazyGitFilter entry point
|
||||||
local function lazygitfilter(path)
|
local function lazygitfilter(path)
|
||||||
if is_lazygit_available() ~= true then
|
if is_lazygit_available() ~= true then
|
||||||
print("Please install lazygit. Check documentation for more information")
|
print("Please install lazygit. Check documentation for more information")
|
||||||
@@ -142,6 +145,7 @@ local function lazygitfilter(path)
|
|||||||
exec_lazygit_command(cmd)
|
exec_lazygit_command(cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- :LazyGitConfig entry point
|
||||||
local function lazygitconfig()
|
local function lazygitconfig()
|
||||||
local os = fn.substitute(fn.system('uname'), '\n', '', '')
|
local os = fn.substitute(fn.system('uname'), '\n', '', '')
|
||||||
local config_file = ""
|
local config_file = ""
|
||||||
@@ -170,10 +174,7 @@ local function lazygitconfig()
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setup = setup,
|
|
||||||
lazygit = lazygit,
|
lazygit = lazygit,
|
||||||
lazygitfilter = lazygitfilter,
|
lazygitfilter = lazygitfilter,
|
||||||
lazygitconfig = lazygitconfig,
|
lazygitconfig = lazygitconfig,
|
||||||
on_exit = on_exit,
|
|
||||||
on_buf_leave = on_buf_leave,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ endif
|
|||||||
|
|
||||||
command! LazyGit lua require'lazygit'.lazygit()
|
command! LazyGit lua require'lazygit'.lazygit()
|
||||||
|
|
||||||
|
command! LazyGitFilter lua require'lazygit'.lazygitfilter()
|
||||||
|
|
||||||
command! LazyGitConfig lua require'lazygit'.lazygitconfig()
|
command! LazyGitConfig lua require'lazygit'.lazygitconfig()
|
||||||
|
|
||||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
|
|||||||
Reference in New Issue
Block a user