Reorder functions
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
|
||||||
|
local file_buffer = nil
|
||||||
|
|
||||||
local OPTIONS = {
|
local OPTIONS = {
|
||||||
lazygit_floating_window_scaling_factor = 0.9,
|
lazygit_floating_window_scaling_factor = 0.9,
|
||||||
lazygit_floating_window_winblend = 0,
|
lazygit_floating_window_winblend = 0,
|
||||||
@@ -15,6 +17,22 @@ local function is_lazygit_available()
|
|||||||
return fn.executable("lazygit") == 1
|
return fn.executable("lazygit") == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function project_root_dir()
|
||||||
|
return fn.system('cd ' .. fn.expand('%:p:h') .. ' && git rev-parse --show-toplevel 2> /dev/null')
|
||||||
|
end
|
||||||
|
|
||||||
|
local function exec_lazygit_command()
|
||||||
|
local current_dir = fn.getcwd()
|
||||||
|
-- TODO: ensure that it is a valid git directory
|
||||||
|
local root_dir = project_root_dir()
|
||||||
|
local cmd = "lazygit " .. "-p " .. root_dir
|
||||||
|
-- ensure that the buffer is closed on exit
|
||||||
|
execute([[
|
||||||
|
call termopen('%s', {'on_exit': {job_id, code, event-> luaeval("require('lazygit').on_exit(" . job_id . "," . code . "," . event . ")")}})
|
||||||
|
]], cmd)
|
||||||
|
vim.cmd "startinsert"
|
||||||
|
end
|
||||||
|
|
||||||
local function open_floating_window()
|
local function open_floating_window()
|
||||||
-- create a unlisted scratch buffer
|
-- create a unlisted scratch buffer
|
||||||
local file_buffer = api.nvim_create_buf(false, true)
|
local file_buffer = api.nvim_create_buf(false, true)
|
||||||
@@ -64,11 +82,13 @@ local function open_floating_window()
|
|||||||
vim.cmd('set winblend=' .. OPTIONS.lazygit_floating_window_winblend)
|
vim.cmd('set winblend=' .. OPTIONS.lazygit_floating_window_winblend)
|
||||||
|
|
||||||
-- use autocommand to ensure that the border_buffer closes at the same time as the main buffer
|
-- use autocommand to ensure that the border_buffer closes at the same time as the main buffer
|
||||||
vim.cmd('au BufWipeout <buffer> silent! execute "silent bwipeout!"' .. border_buffer)
|
vim.cmd('autocmd BufWipeout <buffer> silent! execute "silent bwipeout!"' .. border_buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function project_root_dir()
|
local function on_buf_leave()
|
||||||
return fn.system('cd ' .. fn.expand('%:p:h') .. ' && git rev-parse --show-toplevel 2> /dev/null')
|
file_buffer = fn.bufnr("%")
|
||||||
|
vim.cmd("hide")
|
||||||
|
vim.cmd("hide")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_exit(job_id, code, event)
|
local function on_exit(job_id, code, event)
|
||||||
@@ -77,18 +97,6 @@ local function on_exit(job_id, code, event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function exec_lazygit_command()
|
|
||||||
local current_dir = fn.getcwd()
|
|
||||||
-- TODO: ensure that it is a valid git directory
|
|
||||||
local root_dir = project_root_dir()
|
|
||||||
local cmd = "lazygit " .. "-p " .. root_dir
|
|
||||||
-- ensure that the buffer is closed on exit
|
|
||||||
execute([[
|
|
||||||
call termopen('%s', {'on_exit': {job_id, code, event-> luaeval("require('lazygit').on_exit(" . job_id . "," . code . "," . event . ")")}})
|
|
||||||
]], cmd)
|
|
||||||
vim.cmd "startinsert"
|
|
||||||
end
|
|
||||||
|
|
||||||
local function lazygit()
|
local function lazygit()
|
||||||
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")
|
||||||
@@ -109,4 +117,5 @@ return {
|
|||||||
setup = setup,
|
setup = setup,
|
||||||
lazygit = lazygit,
|
lazygit = lazygit,
|
||||||
on_exit = on_exit,
|
on_exit = on_exit,
|
||||||
|
on_buf_leave = on_buf_leave,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user