dotfiles/.config/nvim/lua/lazygit_integration.lua

45 lines
1.1 KiB
Lua
Raw Normal View History

local M = {}
M.run = function()
vim.api.nvim_create_autocmd({"TermClose"}, {
pattern= { "term://*lazygit" },
callback = function()
vim.api.nvim_input("<CR>")
end
})
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
local width = vim.api.nvim_get_option("columns")
local height = vim.api.nvim_get_option("lines")
local win_width = math.ceil(width * 0.8)
local win_height = math.ceil(height * 0.8 - 4)
local col = math.ceil((width - win_width) / 2 - 1)
local row = math.ceil((height - win_height) / 2 - 1)
local opts = {
style = "minimal",
relative = "editor",
width = win_width,
height = win_height,
row = row,
col = col,
border = "rounded"
}
local win = vim.api.nvim_open_win(buf, true, opts)
vim.api.nvim_win_set_option(win, "cursorline", true)
vim.api.nvim_buf_set_option(buf, "modifiable", true)
vim.api.nvim_cmd({cmd="terminal", args={"lazygit"}}, {})
vim.cmd('startinsert')
vim.api.nvim_buf_set_option(buf, "modifiable", true)
end
return M