Skip to content

Commit

Permalink
feat(git): <leader>gb for Git Blame Line
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Apr 11, 2024
1 parent 32eacde commit 9e3af10
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lua/lazyvim/config/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ map("n", "<leader>ub", function() LazyVim.toggle("background", false, {"light",
-- lazygit
map("n", "<leader>gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" })
map("n", "<leader>gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" })
map("n", "<leader>gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" })

map("n", "<leader>gf", function()
local git_path = vim.api.nvim_buf_get_name(0)
Expand Down
18 changes: 18 additions & 0 deletions lua/lazyvim/util/lazygit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9e3af10

Please sign in to comment.