lazygit.nvim
lazygit.nvim copied to clipboard
open at current buffer's git repo
hi, i was trying to figure out a way to open lazygit at the git repo of the currently active buffer, and came across this code at https://github.com/kdheepak/lazygit.nvim/blob/main/lua/lazygit/utils.lua#L63:
local cmd = string.format('cd "%s" && git rev-parse --show-toplevel', fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h'), root)
apologies if it's a lua feature i'm not familiar with, but it seems like root
is an unused string.format
parameter there?
it would also be a nice enhancement when the path
parameter is provided to lazygit(path)
to open at the toplevel dir, so that -p <path>
doesn't fail when not at the toplevel (..and since all the hard work is done in that function anyway to add it to the list of recently opened repos)
currently i've hacked together this code to do so:
function _G.lazygit_at_buffer()
local cmd = string.format('cd "%s" && git rev-parse --show-toplevel', vim.fn.fnamemodify(vim.fn.resolve(vim.fn.expand('%:p')), ':h'))
local gitdir = vim.fn.system(cmd)
local isgitdir = vim.fn.matchstr(gitdir, '^fatal:.*') == ''
if not isgitdir then
gitdir = nil
end
require('lazygit').lazygit(gitdir)
end
thanks!