-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
neovim: Rewrite lazygit integration using toggleterm
- Loading branch information
1 parent
bfa65d2
commit f1c7d21
Showing
3 changed files
with
23 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,30 @@ | ||
-- Do not show 'Process exited' message when closing lazygit buffer | ||
local nvim_terminal_augroup = vim.api.nvim_create_augroup('nvim_terminal', { clear = false }) | ||
require("toggleterm").setup{} | ||
|
||
vim.api.nvim_create_autocmd({ 'TermClose' }, { | ||
group = nvim_terminal_augroup, | ||
desc = 'Automatically close buffers after running lazygit', | ||
pattern = 'term://*:lazygit', | ||
callback = function(args) | ||
if vim.v.event.status == 0 then | ||
vim.cmd({ cmd = 'bdelete', args = { args.buf }, bang = true }) | ||
end | ||
end, | ||
}) | ||
|
||
-- Open Lazygit in a floating window | ||
function Lazygit() | ||
local width = vim.api.nvim_get_option("columns") | ||
local height = vim.api.nvim_get_option("lines") | ||
local Terminal = require('toggleterm.terminal').Terminal | ||
|
||
local buffer = vim.api.nvim_create_buf(false, true) | ||
local win = vim.api.nvim_open_win(buffer, false, { | ||
relative = 'editor', | ||
local lazygit = Terminal:new({ | ||
cmd = "lazygit", | ||
display_name = "lazygit", | ||
close_on_exit = true, | ||
direction = "float", | ||
float_opts = { | ||
border = "none", | ||
row = 0, | ||
col = 0, | ||
width = width, | ||
height = height - 1, | ||
style = 'minimal', | ||
zindex = 1000 | ||
}) | ||
|
||
-- override float background color to be the same as the normal background | ||
vim.api.nvim_set_option_value('winhl', 'NormalFloat:Normal', {win = win}) | ||
width = function() | ||
return vim.api.nvim_get_option("columns") | ||
end, | ||
height = function() | ||
return vim.api.nvim_get_option("lines") - 1 | ||
end, | ||
zindex = 1001, | ||
} | ||
}) | ||
|
||
vim.api.nvim_set_current_win(win) | ||
vim.fn.termopen("lazygit") | ||
vim.cmd("startinsert") | ||
function LazygitOpen() | ||
lazygit:open() | ||
end | ||
|
||
function LazygitClose() | ||
local win = vim.api.nvim_get_current_win() | ||
local buf = vim.api.nvim_win_get_buf(win) | ||
vim.api.nvim_win_close(win, true) | ||
vim.api.nvim_buf_delete(buf, { force = true }) | ||
lazygit:shutdown() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters