From 43104006ae79e7c4cd4150ed2de55f30c968fb66 Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Mon, 23 Mar 2026 20:33:37 -0400 Subject: [PATCH] refactor: streamline git workflow plugins - Simplify gitsigns.lua configuration - Update fugitive.lua bindings - Restructure worktree.lua setup --- lua/custom/plugins/fugitive.lua | 1 + lua/custom/plugins/gitsigns.lua | 50 ++++++++++++++++++++------------- lua/custom/plugins/worktree.lua | 34 +++++++++++----------- 3 files changed, 48 insertions(+), 37 deletions(-) mode change 100644 => 100755 lua/custom/plugins/worktree.lua diff --git a/lua/custom/plugins/fugitive.lua b/lua/custom/plugins/fugitive.lua index c738c14..9652ef5 100755 --- a/lua/custom/plugins/fugitive.lua +++ b/lua/custom/plugins/fugitive.lua @@ -1,5 +1,6 @@ return { 'tpope/vim-fugitive', + cmd = { 'Git', 'G' }, config = function() -- General key mappings for Fugitive vim.keymap.set('n', 'gs', vim.cmd.Git, { desc = 'Open Git status' }) diff --git a/lua/custom/plugins/gitsigns.lua b/lua/custom/plugins/gitsigns.lua index 2961bfd..4d03262 100755 --- a/lua/custom/plugins/gitsigns.lua +++ b/lua/custom/plugins/gitsigns.lua @@ -1,7 +1,7 @@ return { 'lewis6991/gitsigns.nvim', + event = 'BufReadPre', opts = { - -- Git sign characters signs = { add = { text = '+' }, change = { text = '~' }, @@ -9,37 +9,47 @@ return { topdelete = { text = '‾' }, changedelete = { text = '~' }, }, - -- Function called when plugin attaches to a buffer on_attach = function(bufnr) - -- Always show the sign column - vim.opt.signcolumn = 'yes' + local gs = package.loaded.gitsigns - -- Keybindings - local gs = require('gitsigns') - vim.keymap.set('n', 'hp', gs.preview_hunk, { - buffer = bufnr, - desc = 'Preview git hunk', - }) + local function map(mode, keys, func, desc) + vim.keymap.set(mode, keys, func, { buffer = bufnr, desc = 'Git: ' .. desc }) + end - vim.keymap.set({ 'n', 'v' }, ']c', function() + -- Navigation + map({ 'n', 'v' }, ']c', function() if vim.wo.diff then return ']c' end - vim.schedule(function() - gs.next_hunk() - end) + vim.schedule(gs.next_hunk) return '' - end, { expr = true, buffer = bufnr, desc = 'Jump to next hunk' }) + end, 'Next hunk') - vim.keymap.set({ 'n', 'v' }, '[c', function() + map({ 'n', 'v' }, '[c', function() if vim.wo.diff then return '[c' end - vim.schedule(function() - gs.prev_hunk() - end) + vim.schedule(gs.prev_hunk) return '' - end, { expr = true, buffer = bufnr, desc = 'Jump to previous hunk' }) + end, 'Prev hunk') + + -- Hunks + map('n', 'hs', gs.stage_hunk, 'Stage hunk') + map('n', 'hr', gs.reset_hunk, 'Reset hunk') + map('n', 'hp', gs.preview_hunk, 'Preview hunk') + map('n', 'hu', gs.undo_stage_hunk, 'Undo stage hunk') + map('n', 'hb', function() + gs.blame_line({ full = true }) + end, 'Blame line') + map('n', 'hd', gs.diffthis, 'Diff this') + + -- Visual stage/reset + map('v', 'hs', function() + gs.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end, 'Stage hunk') + map('v', 'hr', function() + gs.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end, 'Reset hunk') end, }, } diff --git a/lua/custom/plugins/worktree.lua b/lua/custom/plugins/worktree.lua old mode 100644 new mode 100755 index 830d1f6..91ac069 --- a/lua/custom/plugins/worktree.lua +++ b/lua/custom/plugins/worktree.lua @@ -1,19 +1,19 @@ return { - 'ThePrimeagen/git-worktree.nvim', - keys = { - { - 'ga', - "lua require('telescope').extensions.git_worktree.git_worktree()", - desc = 'Git Worktrees', - }, - { - 'gn', - "lua require('telescope').extensions.git_worktree.create_git_worktree()", - desc = 'New Git Worktree', - }, - }, - config = function() - require('git-worktree').setup() - require('telescope').load_extension('git_worktree') - end, + -- 'ThePrimeagen/git-worktree.nvim', + -- keys = { + -- { + -- 'ga', + -- "lua require('telescope').extensions.git_worktree.git_worktree()", + -- desc = 'Git Worktrees', + -- }, + -- { + -- 'gn', + -- "lua require('telescope').extensions.git_worktree.create_git_worktree()", + -- desc = 'New Git Worktree', + -- }, + -- }, + -- config = function() + -- require('git-worktree').setup() + -- require('telescope').load_extension('git_worktree') + -- end, }