From ad6eb7ed0b599da6464f1c71db55107f8988dfde Mon Sep 17 00:00:00 2001 From: Uthman Mohamed <83053931+1239uth@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:02:28 -0400 Subject: [PATCH] Add gf for lazygit commit history on current file --- lua/lazyvim/config/keymaps.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index 1e7cc1a2..715fb87c 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -129,6 +129,20 @@ 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 path = vim.fn.expand("%:p") + local root = Util.root() + if not path:find(root, 1, true) then + return path + end + return path:sub(#root + 2) +end + +map("n", "gf", function() + Util.terminal({ "lazygit", "-f", current_file_path_from_root_dir() }, { esc_esc = false, ctrl_hjkl = false }) +end, { desc = "Lazygit current file history" }) + -- quit map("n", "qq", "qa", { desc = "Quit all" })