vim.pack.add({ 'https://github.com/tpope/vim-fugitive', }) 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 map('n', '', 'Gitonly') 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)