local function current_file_location() local root = vim.trim(vim.fn.system("git rev-parse --show-toplevel")) if vim.v.shell_error ~= 0 or root == "" then return nil end local path = vim.api.nvim_buf_get_name(0) if path == "" then return nil end local prefix = root .. "/" if path:sub(1, #prefix) ~= prefix then return nil end local rel = path:sub(#prefix + 1) return ("%s:%d"):format(rel, vim.fn.line(".")) end local function gh_browse() if vim.fn.executable("gh") ~= 1 then vim.notify("gh CLI not found", vim.log.levels.WARN) return end local loc = current_file_location() if loc then vim.system({ "gh", "browse", loc }) return end vim.system({ "gh", "browse" }) end return { -- Fugitive: The gold standard for Git in Vim { "tpope/vim-fugitive", cmd = { "Git", "G", "Gread", "Gwrite", "Gdiffsplit", "Gvdiffsplit", "Gblame" }, keys = { { "gg", "Gitonly", desc = "Git status (fullscreen)" }, { "gc", "Git commit", desc = "Git commit" }, { "gp", "Git push", desc = "Git push" }, { "gl", "Git pull", desc = "Git pull" }, { "gb", "Git blame", desc = "Git blame" }, { "gd", "Gvdiffsplit", desc = "Git diff vertical" }, { "gr", "Gread", desc = "Git checkout file" }, { "gw", "Gwrite", desc = "Git add file" }, { "go", gh_browse, desc = "Open in GitHub" }, }, }, -- Gitsigns: Git info in the gutter { "lewis6991/gitsigns.nvim", event = { "BufReadPre", "BufNewFile" }, opts = { signs = { add = { text = "│" }, change = { text = "│" }, delete = { text = "_" }, topdelete = { text = "‾" }, changedelete = { text = "│" }, }, signs_staged = { add = { text = "┃" }, change = { text = "┃" }, delete = { text = "_" }, topdelete = { text = "‾" }, changedelete = { text = "┃" }, }, signs_staged_enable = true, signcolumn = true, numhl = false, linehl = false, -- disabled - let colorscheme handle word_diff = false, current_line_blame = false, current_line_blame_opts = { delay = 500, }, }, keys = { { "]g", "Gitsigns next_hunk", desc = "Next hunk" }, { "[g", "Gitsigns prev_hunk", desc = "Prev hunk" }, { "ghs", "Gitsigns stage_hunk", desc = "Stage hunk" }, { "ghr", "Gitsigns reset_hunk", desc = "Reset hunk" }, { "ghp", "Gitsigns preview_hunk", desc = "Preview hunk" }, { "gB", "Gitsigns toggle_current_line_blame", desc = "Toggle line blame" }, }, }, -- Diffs.nvim: Better diff highlighting { "barrettruth/diffs.nvim", lazy = false, init = function() vim.g.diffs = { fugitive = { enabled = true, horizontal = false, vertical = false, }, hide_prefix = true, highlights = { gutter = true, blend_alpha = 0.4, intra = { enabled = true, }, }, } end, }, }