diff options
| author | Trey Bastian <hello@treybastian.com> | 2026-06-06 11:38:30 +0100 |
|---|---|---|
| committer | Trey Bastian <hello@treybastian.com> | 2026-06-06 11:38:30 +0100 |
| commit | 25a0b6eb45d9fa42cfdcf01e2a1a6fea0d4f9635 (patch) | |
| tree | b4cc95d8e8b020bfb2762bb98fc017f68a82e082 /lua/config | |
| parent | dfcc8771d060785c5f5b842db269d0dedbd40815 (diff) | |
trying out lazygit
Diffstat (limited to 'lua/config')
| -rw-r--r-- | lua/config/git.lua | 62 | ||||
| -rw-r--r-- | lua/config/plugins.lua | 2 |
2 files changed, 55 insertions, 9 deletions
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", "<leader>gp", function() - vim.cmd.Git({ "push" }) -end) +local lazygit_buf = nil +local lazygit_win = nil -vim.keymap.set("n", "<leader>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", "<leader>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", "<leader>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", |
