From dec4c0f45146ef98f5caa7c85ea8715acd8a4ec8 Mon Sep 17 00:00:00 2001 From: Uthman Mohamed <83053931+1239uth@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:27:38 -0400 Subject: [PATCH] Change root dir to git root using git command --- lua/lazyvim/config/keymaps.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index 715fb87c..88408c68 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -129,10 +129,9 @@ map("n", "ub", function() Util.toggle("background", false, {"light", "da map("n", "gg", function() Util.terminal({ "lazygit" }, { cwd = Util.root(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" }) map("n", "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", "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