local function file_loc() 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 == '' or path:sub(1, #root + 1) ~= root .. '/' then return nil end return ('%s:%d'):format(path:sub(#root + 2), 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 = file_loc() if loc then vim.system({ 'gh', 'browse', loc }) else vim.system({ 'gh', 'browse' }) end end return { { 'tpope/vim-fugitive', config = function() map('n', 'gg', 'Gitonly') map('n', 'gc', 'Git commit') map('n', 'gp', 'Git push') map('n', 'gl', 'Git pull') map('n', 'gb', 'Git blame') map('n', 'gd', 'Gvdiffsplit') map('n', 'gr', 'Gread') map('n', 'gw', 'Gwrite') map({ 'n', 'v' }, 'go', gh_browse) end, }, { 'lewis6991/gitsigns.nvim', 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, }, config = function(_, opts) require('gitsigns').setup(opts) map('n', ']g', 'Gitsigns next_hunk') map('n', '[g', 'Gitsigns prev_hunk') map('n', 'ghs', 'Gitsigns stage_hunk') map('n', 'ghr', 'Gitsigns reset_hunk') map('n', 'ghp', 'Gitsigns preview_hunk') map('n', 'gB', 'Gitsigns toggle_current_line_blame') end, }, { 'barrettruth/diffs.nvim', enabled = true, init = function() vim.g.diffs = { fugitive = { enabled = true, horizontal = false, vertical = false, }, hide_prefix = true, highlights = { gutter = true, blend_alpha = 0.3, intra = { enabled = true }, }, } end, }, }