From a7ac4e76eacaaf97713423273809d1698cccb013 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sun, 24 Aug 2025 02:36:51 -0400 Subject: [PATCH] turns out gitsigns is actually very useful --- lua/conf/plugins/gitsigns.lua | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lua/conf/plugins/gitsigns.lua diff --git a/lua/conf/plugins/gitsigns.lua b/lua/conf/plugins/gitsigns.lua new file mode 100644 index 0000000..9d97192 --- /dev/null +++ b/lua/conf/plugins/gitsigns.lua @@ -0,0 +1,85 @@ +local map = core.misc.map + +return { "lewis6991/gitsigns.nvim", + lazy = function(load) + load:auto({ "BufEnter", "BufNew" }, { + callback = function() + local paths = vim.fs.find({ ".git", }, { upward = true }) + if #paths > 0 then + load:cleanup() + end + end + }) + load:cmd("Gitsigns") + end, + load = function() + local gs = require("gitsigns") + + gs.setup { + signs = { + add = { text = "│" }, + change = { text = "│" }, + delete = { text = "-" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + untracked = { text = "┆" } + }, + + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + + watch_gitdir = { + interval = 1000, + follow_files = true + }, + + attach_to_untracked = true, + current_line_blame_formatter = ", - ", + + preview_config = { border = vim.g.border_style }, + + on_attach = function(bufnr) + local opts = { buffer = bufnr } + + -- Navigation + map("n", "]c", function() + if vim.wo.diff then + return "]c" + end + vim.schedule(function() gs.next_hunk() end) + end, { expr = true, buffer = bufnr }) + + map("n", "[c", function() + if vim.wo.diff then + return "[c" + end + vim.schedule(function() gs.prev_hunk() end) + end, { expr = true, buffer = bufnr }) + + -- Actions + map("n", "hs", gs.stage_hunk, opts) + map("n", "hr", gs.reset_hunk, opts) + map("v", "hs", function() + gs.stage_hunk { vim.fn.line("."), vim.fn.line("v") } + end, opts) + map("v", "hr", function() + gs.reset_hunk { vim.fn.line("."), vim.fn.line("v") } + end, opts) + map("n", "hS", gs.stage_buffer, opts) + map("n", "hu", gs.undo_stage_hunk, opts) + map("n", "hR", gs.reset_buffer, opts) + map("n", "hp", gs.preview_hunk, opts) + map("n", "hb", function() gs.blame_line { full = true } end, opts) + map("n", "tb", gs.toggle_current_line_blame, opts) + map("n", "hd", gs.diffthis, opts) + map("n", "hD", function() gs.diffthis("~") end, opts) + map("n", "td", gs.toggle_deleted, opts) + + -- Text object + map({ "o", "x" }, "ih", ":Gitsigns select_hunk", opts) + end + } + end +}