From f14182a1ceff287d66c5ec3770601da35d143f9e Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Sun, 17 Mar 2024 00:58:01 +1030 Subject: [PATCH] feat: add keybind to show selection git history --- .config/aliasrc | 1 + .config/nvim/lua/settings/theme.lua | 4 ++-- .config/nvim/lua/tovi/plugins/fugitive.lua | 25 ++++++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.config/aliasrc b/.config/aliasrc index 05d87ce..52107f3 100644 --- a/.config/aliasrc +++ b/.config/aliasrc @@ -26,6 +26,7 @@ alias \ lf="lfcd" \ dcu='docker compose up' \ dce='docker compose exec' \ + dcr='docker compose run' \ dps="docker ps" \ ds="docker stop" \ dce-test='docker compose exec fpm ./artisan test' \ diff --git a/.config/nvim/lua/settings/theme.lua b/.config/nvim/lua/settings/theme.lua index 680655a..583ec66 100644 --- a/.config/nvim/lua/settings/theme.lua +++ b/.config/nvim/lua/settings/theme.lua @@ -1,5 +1,5 @@ -- Themery block -- This block will be replaced by Themery. -vim.cmd("colorscheme nightfly") -vim.g.theme_id = 3 +vim.cmd("colorscheme carbonfox") +vim.g.theme_id = 2 -- end themery block diff --git a/.config/nvim/lua/tovi/plugins/fugitive.lua b/.config/nvim/lua/tovi/plugins/fugitive.lua index b2f915d..6b8a2c5 100644 --- a/.config/nvim/lua/tovi/plugins/fugitive.lua +++ b/.config/nvim/lua/tovi/plugins/fugitive.lua @@ -7,13 +7,10 @@ return { vim.opt.diffopt = vim.opt.diffopt + "vertical" vim.opt.display = vim.opt.display + "lastline" - vim.api.nvim_set_keymap("n", "gl", ":GBrowse", { noremap = true }) - vim.cmd([[ let g:fugitive_gitlab_domains = {"ssh://code.codium.com.au": "https://code.codium.com.au"} ]]) - 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 -L %s %s | awk '{print $1}'", vim.fn.shellescape(vim.fn.fnamemodify(current_file, ':h')), range, vim.fn.fnamemodify(current_file, ':t')) + 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") @@ -22,7 +19,7 @@ return { return result end - vim.keymap.set('n', 'gc', function () + vim.keymap.set('n', 'gC', function () vim.cmd(string.format('Git show %s', gitBlame({vim.fn.line('.'), vim.fn.line('.')}))) end) @@ -34,6 +31,22 @@ return { 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('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('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, }