mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
Change root dir to git root using git command
This commit is contained in:
parent
ad6eb7ed0b
commit
dec4c0f451
1 changed files with 3 additions and 4 deletions
|
|
@ -129,10 +129,9 @@ map("n", "<leader>ub", function() Util.toggle("background", false, {"light", "da
|
|||
map("n", "<leader>gg", function() Util.terminal({ "lazygit" }, { cwd = Util.root(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" })
|
||||
map("n", "<leader>gG", function() Util.terminal({ "lazygit" }, {esc_esc = false, ctrl_hjkl = false}) end, { desc = "Lazygit (cwd)" })
|
||||
|
||||
-- Function to get the current file path from the root directory
|
||||
local current_file_path_from_root_dir = function()
|
||||
local current_file_path_from_git_root = function()
|
||||
local path = vim.fn.expand("%:p")
|
||||
local root = Util.root()
|
||||
local root = vim.fn.system("git -C " .. path .. " rev-parse --show-toplevel"):gsub("\n$", "")
|
||||
if not path:find(root, 1, true) then
|
||||
return path
|
||||
end
|
||||
|
|
@ -140,7 +139,7 @@ local current_file_path_from_root_dir = function()
|
|||
end
|
||||
|
||||
map("n", "<leader>gf", function()
|
||||
Util.terminal({ "lazygit", "-f", current_file_path_from_root_dir() }, { esc_esc = false, ctrl_hjkl = false })
|
||||
Util.terminal({ "lazygit", "-f", current_file_path_from_git_root() }, { esc_esc = false, ctrl_hjkl = false })
|
||||
end, { desc = "Lazygit current file history" })
|
||||
|
||||
-- quit
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue