|
5 | 5 | return { |
6 | 6 | { |
7 | 7 | 'lewis6991/gitsigns.nvim', |
| 8 | + dependencies = { |
| 9 | + 'akinsho/toggleterm.nvim', |
| 10 | + }, |
8 | 11 | opts = { |
9 | 12 | on_attach = function(bufnr) |
10 | 13 | local gitsigns = require 'gitsigns' |
@@ -55,6 +58,33 @@ return { |
55 | 58 | -- Toggles |
56 | 59 | map('n', '<leader>tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) |
57 | 60 | map('n', '<leader>tD', gitsigns.preview_hunk_inline, { desc = '[T]oggle git show [D]eleted' }) |
| 61 | + |
| 62 | + -- Viewing the full git diff of the blame under cursor |
| 63 | + map('n', '<leader>hv', function() |
| 64 | + local file = vim.fn.expand '%' |
| 65 | + local line = vim.fn.line '.' |
| 66 | + local blame_output = vim.fn.systemlist(string.format('git blame -L %d,+1 --porcelain -- %s', line, file)) |
| 67 | + if not blame_output or #blame_output == 0 then |
| 68 | + print 'No blame info available :(' |
| 69 | + return |
| 70 | + end |
| 71 | + |
| 72 | + local commit = blame_output[1]:match '^(%w+)%s' |
| 73 | + if not commit then |
| 74 | + print('Could not extract commit hash from blame: ' .. blame_output[1]) |
| 75 | + return |
| 76 | + end |
| 77 | + |
| 78 | + local Terminal = require('toggleterm.terminal').Terminal |
| 79 | + local git_show_term = Terminal:new { |
| 80 | + cmd = 'git show ' .. commit, |
| 81 | + direction = 'float', -- or 'horizontal' / 'vertical' |
| 82 | + close_on_exit = true, |
| 83 | + hidden = true, |
| 84 | + } |
| 85 | + |
| 86 | + git_show_term:toggle() |
| 87 | + end, { desc = 'git blame on current line and [v]iew diff for that SHA in toggleterm' }) |
58 | 88 | end, |
59 | 89 | signs = { -- See `:help gitsigns` to understand what the configuration keys do |
60 | 90 | add = { text = '+' }, |
|
0 commit comments