return { "tpope/vim-fugitive", dependencies = { "shumphrey/fugitive-gitlab.vim", }, config = function() vim.opt.diffopt = vim.opt.diffopt + "vertical" vim.opt.display = vim.opt.display + "lastline" local function gitBlame(lines) local current_file = vim.fn.expand('%:p') local range = lines[1] .. "," .. lines[2] local cmd = string.format("git -C %s blame -C -C -C -L %s %s | awk '{print $1}'", vim.fn.shellescape(vim.fn.fnamemodify(current_file, ':h')), range, vim.fn.fnamemodify(current_file, ':t')) local handle = io.popen(cmd) local result = handle:read("*a") handle:close() return result end vim.keymap.set('n', 'gC', function () vim.cmd(string.format('Git show %s', gitBlame({vim.fn.line('.'), vim.fn.line('.')}))) end) local options = { noremap = true, silent = true } vim.keymap.set('n', 'gg', 'Git', options) vim.keymap.set('n', 'gp', 'Git push', options) vim.keymap.set('n', 'gP', 'Git pull', options) vim.keymap.set('n', 'ga', 'Git add .', options) vim.keymap.set('n', 'gA', 'Git add', options) vim.keymap.set('n', 'gc', 'Git commit', options) -- vim.keymap.set('n', 'gC', 'Git commit -a', options) vim.keymap.set('v', 'gl', function () local startPos = vim.fn.getpos("'<") local endPos = vim.fn.getpos("'>") local startLine = startPos[2] local endLine = endPos[2] if (startLine == 0 or endLine == 0) then vim.notify(vim.inspect(vim.fn.getpos("'<")) .. " to " .. vim.inspect(vim.fn.getpos("'>"))) -- vim.notify('Error getting start or end line', vim.log.levels.ERROR) return end vim.cmd(string.format('Git log -L %d,%d:%s', startLine, endLine, vim.fn.expand("%:."))) end, options); end, }