From 37a4ab0a6e160ab8a6ccc43db5fe3323b3c9c856 Mon Sep 17 00:00:00 2001 From: cnrrobertson Date: Tue, 25 Oct 2022 16:16:48 -0400 Subject: [PATCH] Add LazyGitCurrentFile command to open floating LazyGit window at project root of current file --- lua/lazygit.lua | 9 +++++++++ plugin/lazygit.vim | 2 ++ 2 files changed, 11 insertions(+) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 7a773a1..ea79486 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -1,5 +1,6 @@ local open_floating_window = require"lazygit.window".open_floating_window local project_root_dir = require"lazygit.utils".project_root_dir +local get_root = require"lazygit.utils".get_root local is_lazygit_available = require"lazygit.utils".is_lazygit_available local is_symlink = require"lazygit.utils".is_symlink @@ -67,6 +68,13 @@ local function lazygit(path) exec_lazygit_command(cmd) end +--- :LazyGitCurrentFile entry point +local function lazygitcurrentfile() + local current_dir = vim.fn.expand('%:p:h') + local git_root = get_root(current_dir) + lazygit(git_root) +end + --- :LazyGitFilter entry point local function lazygitfilter(path) if is_lazygit_available() ~= true then @@ -120,6 +128,7 @@ end return { lazygit = lazygit, + lazygitcurrentfile = lazygitcurrentfile, lazygitfilter = lazygitfilter, lazygitfiltercurrentfile = lazygitfiltercurrentfile, lazygitconfig = lazygitconfig, diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index 2722161..ef1fac2 100644 --- a/plugin/lazygit.vim +++ b/plugin/lazygit.vim @@ -25,6 +25,8 @@ endif command! LazyGit lua require'lazygit'.lazygit() +command! LazyGitCurrentFile lua require'lazygit'.lazygitcurrentfile() + command! LazyGitFilter lua require'lazygit'.lazygitfilter() command! LazyGitFilterCurrentFile lua require'lazygit'.lazygitfiltercurrentfile()