Merge pull request #13 from kdheepak/kd/use-neovim-lua-callback
Use latest neovim lua native callback
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
vim = vim
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
|
||||||
@@ -30,14 +31,19 @@ local function project_root_dir()
|
|||||||
return fn.getcwd(0, 0)
|
return fn.getcwd(0, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function on_exit(job_id, code, event)
|
||||||
|
if code == 0 then
|
||||||
|
-- delete terminal buffer
|
||||||
|
vim.cmd("silent! bdelete!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
-- ensure that the buffer is closed on exit
|
-- ensure that the buffer is closed on exit
|
||||||
execute([[
|
vim.fn.termopen(cmd, { on_exit = on_exit })
|
||||||
call termopen('%s', {'on_exit': {job_id, code, event-> luaeval("require('lazygit').on_exit(" . job_id . "," . code . "," . event . ")")}})
|
|
||||||
]], cmd)
|
|
||||||
vim.cmd "startinsert"
|
vim.cmd "startinsert"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -105,13 +111,6 @@ local function open_floating_window()
|
|||||||
vim.cmd(cmd:format(file_buffer, border_buffer))
|
vim.cmd(cmd:format(file_buffer, border_buffer))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_exit(job_id, code, event)
|
|
||||||
if code == 0 then
|
|
||||||
-- delete terminal buffer
|
|
||||||
vim.cmd("silent! bdelete!")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user