From 25a0b6eb45d9fa42cfdcf01e2a1a6fea0d4f9635 Mon Sep 17 00:00:00 2001 From: Trey Bastian Date: Sat, 6 Jun 2026 11:38:30 +0100 Subject: trying out lazygit --- lua/config/git.lua | 62 ++++++++++++++++++++++++++++++++++++++++++++------ lua/config/plugins.lua | 2 -- 2 files changed, 55 insertions(+), 9 deletions(-) (limited to 'lua/config') diff --git a/lua/config/git.lua b/lua/config/git.lua index 366ca77..41b4f5a 100644 --- a/lua/config/git.lua +++ b/lua/config/git.lua @@ -2,12 +2,60 @@ vim.pack.add({ "https://github.com/tpope/vim-fugitive", }) -vim.keymap.set("n", "gp", function() - vim.cmd.Git({ "push" }) -end) +local lazygit_buf = nil +local lazygit_win = nil -vim.keymap.set("n", "gP", function() - vim.cmd.Git({ "pull --rebase" }) -end) +local function get_geometry() + local width = math.floor(vim.o.columns * 0.8) + local height = math.floor(vim.o.lines * 0.8) + return { + relative = "editor", + row = math.floor((vim.o.lines - height) / 2), + col = math.floor((vim.o.columns - width) / 2), + width = width, + height = height, + border = "rounded", + style = "minimal", + } +end -vim.keymap.set("n", "gs", vim.cmd.Git) +local function toggle_lazygit() + if lazygit_win and vim.api.nvim_win_is_valid(lazygit_win) then + vim.api.nvim_win_close(lazygit_win, true) + lazygit_win = nil + return + end + + if not lazygit_buf or not vim.api.nvim_buf_is_valid(lazygit_buf) then + lazygit_buf = vim.api.nvim_create_buf(false, true) + end + + lazygit_win = vim.api.nvim_open_win(lazygit_buf, true, get_geometry()) + + local autocmd_id + autocmd_id = vim.api.nvim_create_autocmd("VimResized", { + callback = function() + if lazygit_win and vim.api.nvim_win_is_valid(lazygit_win) then + vim.api.nvim_win_set_config(lazygit_win, get_geometry()) + else + vim.api.nvim_del_autocmd(autocmd_id) + end + end, + }) + + if vim.bo[lazygit_buf].buftype ~= "terminal" then + vim.fn.termopen("lazygit", { + on_exit = function() + if lazygit_win and vim.api.nvim_win_is_valid(lazygit_win) then + vim.api.nvim_win_close(lazygit_win, true) + lazygit_win = nil + end + lazygit_buf = nil + end, + }) + end + + vim.cmd("startinsert") +end + +vim.keymap.set("n", "gg", toggle_lazygit) diff --git a/lua/config/plugins.lua b/lua/config/plugins.lua index f9dc5ea..5c2ceda 100644 --- a/lua/config/plugins.lua +++ b/lua/config/plugins.lua @@ -1,7 +1,5 @@ -- plugins that require little no configuration vim.pack.add({ - "https://github.com/tpope/vim-eunuch", - "https://github.com/jessarcher/vim-heritage", "https://github.com/windwp/nvim-autopairs", "https://github.com/kylechui/nvim-surround", "https://github.com/f-person/auto-dark-mode.nvim", -- cgit v1.2.3