From a66ee40f2e8e3d7efd55b8ad4de0daf5d104e807 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Wed, 29 Nov 2023 09:07:46 +1030 Subject: [PATCH] Add keybind to show commit from current line --- .config/nvim/lua/tovi/plugins/formatting.lua | 16 ++++++++-------- .config/nvim/lua/tovi/plugins/fugitive.lua | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.config/nvim/lua/tovi/plugins/formatting.lua b/.config/nvim/lua/tovi/plugins/formatting.lua index 12bd447..78bb100 100644 --- a/.config/nvim/lua/tovi/plugins/formatting.lua +++ b/.config/nvim/lua/tovi/plugins/formatting.lua @@ -19,14 +19,14 @@ return { shell = { "shfmt", "shellcheck" }, python = { "isort", "black" }, }, - format_on_save = { - lsp_fallback = true, - async = false, - timeout_ms = 500, - }, - format_after_save = { - lsp_fallback = true, - }, + -- format_on_save = { + -- lsp_fallback = true, + -- async = false, + -- timeout_ms = 500, + -- }, + -- format_after_save = { + -- lsp_fallback = true, + -- }, log_level = vim.log.levels.WARN, notify_on_error = false, }) diff --git a/.config/nvim/lua/tovi/plugins/fugitive.lua b/.config/nvim/lua/tovi/plugins/fugitive.lua index c20c4ef..773b1dc 100644 --- a/.config/nvim/lua/tovi/plugins/fugitive.lua +++ b/.config/nvim/lua/tovi/plugins/fugitive.lua @@ -9,5 +9,21 @@ return { 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 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) end, }