From 9e3af1070fc1932da322105708ebb32a2cd9572b Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 11 Apr 2024 17:23:46 +0200 Subject: [PATCH] feat(git): `gb` for Git Blame Line --- lua/lazyvim/config/keymaps.lua | 1 + lua/lazyvim/util/lazygit.lua | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index 49f693c948..38c0ae4e9e 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -127,6 +127,7 @@ map("n", "ub", function() LazyVim.toggle("background", false, {"light", -- lazygit map("n", "gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) map("n", "gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" }) +map("n", "gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" }) map("n", "gf", function() local git_path = vim.api.nvim_buf_get_name(0) diff --git a/lua/lazyvim/util/lazygit.lua b/lua/lazyvim/util/lazygit.lua index 7a7af81ebe..1b0d39220e 100644 --- a/lua/lazyvim/util/lazygit.lua +++ b/lua/lazyvim/util/lazygit.lua @@ -140,4 +140,22 @@ gui: M.dirty = false end +---@param opts? {count?: number}|LazyCmdOptions +function M.blame_line(opts) + opts = vim.tbl_deep_extend("force", { + count = 3, + filetype = "git", + size = { + width = 0.6, + height = 0.6, + }, + border = "rounded", + }, opts or {}) + local cursor = vim.api.nvim_win_get_cursor(0) + local line = cursor[1] - 1 + local file = vim.api.nvim_buf_get_name(0) + local cmd = { "git", "log", "-n", opts.count, "-u", "-L", line .. ",+1:" .. file } + return require("lazy.util").float_cmd(cmd, opts) +end + return M