diff --git a/README.md b/README.md index 4d29c5b..2b17cde 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ The following are configuration options and their defaults. let g:lazygit_floating_window_winblend = 0 " transparency of floating window let g:lazygit_floating_window_scaling_factor = 0.9 " scaling factor for floating window let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯'] " customize lazygit popup window corner characters -let g:lazygit_use_neovim_remote = 1 " for neovim-remote support +let g:lazygit_floating_window_use_plenary = 0 " use plenary.nvim to manage floating window if available +let g:lazygit_use_neovim_remote = 1 " fallback to 0 if neovim-remote is not installed ``` Call `:LazyGit` to start a floating window with `lazygit`. diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 2d86cc1..648b880 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -18,10 +18,17 @@ end --- Get project_root_dir for git repository local function project_root_dir() + -- always use bash local oldshell = vim.o.shell vim.o.shell = 'bash' + -- try submodule first + local gitdir = fn.system('cd "' .. fn.expand('%:p:h') .. '" && git rev-parse --show-superproject-working-tree') + if gitdir ~= "" then + return trim(gitdir) + end + -- try file location first local gitdir = fn.system('cd "' .. fn.expand('%:p:h') .. '" && git rev-parse --show-toplevel') local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == "" @@ -74,6 +81,12 @@ local function open_floating_window() floating_window_scaling_factor = floating_window_scaling_factor[false] end + local status, plenary = pcall(require, 'plenary.window.float') + if status and vim.g.lazygit_floating_window_use_plenary and vim.g.lazygit_floating_window_use_plenary ~= 0 then + plenary.percentage_range_window(floating_window_scaling_factor, floating_window_scaling_factor) + return + end + local height = math.ceil(vim.o.lines * floating_window_scaling_factor) - 1 local width = math.ceil(vim.o.columns * floating_window_scaling_factor) @@ -154,7 +167,13 @@ local function lazygit(path) path = project_root_dir() end open_floating_window() - local cmd = "lazygit " .. "-p " .. path + local cmd = "lazygit" + if not vim.env.GIT_DIR then + cmd = cmd .. " -g \"" .. path .. "/.git/\"" + end + if not vim.env.GIT_WORK_TREE then + cmd = cmd .. " -w \"" .. path .. "\"" + end exec_lazygit_command(cmd) end diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index 01514cd..7655ff4 100644 --- a/plugin/lazygit.vim +++ b/plugin/lazygit.vim @@ -16,7 +16,7 @@ if !exists('g:lazygit_floating_window_scaling_factor') endif if !exists('g:lazygit_use_neovim_remote') - let g:lazygit_use_neovim_remote = 1 + let g:lazygit_use_neovim_remote = executable('nvr') ? 1 : 0 endif if !exists('g:lazygit_floating_window_corner_chars') diff --git a/tests/MINRC b/tests/MINRC index aaf2106..553843c 100644 --- a/tests/MINRC +++ b/tests/MINRC @@ -11,7 +11,7 @@ endif call plug#begin('~/.local/share/nvim/plugged') -Plug '~/gitrepos/lazygit.vim' +Plug '~/gitrepos/lazygit.nvim' " Initialize plugin system call plug#end()