diff --git a/lua/lualine/components/branch/git_branch.lua b/lua/lualine/components/branch/git_branch.lua index dcc9775ff..0daaab63a 100644 --- a/lua/lualine/components/branch/git_branch.lua +++ b/lua/lualine/components/branch/git_branch.lua @@ -77,6 +77,14 @@ function M.find_git_dir(dir_path) -- get file dir so we can search from that dir local file_dir = dir_path or vim.fn.expand('%:p:h') + local oil_exists, oil = pcall(require, 'oil') + if oil_exists then + local ok, dir = pcall(oil.get_current_dir) + if ok and dir and dir ~= '' then + file_dir = vim.fn.fnamemodify(dir, ":p:h") + end + end + -- extract correct file dir from terminals if file_dir and file_dir:match('term://.*') then file_dir = vim.fn.expand(file_dir:gsub('term://(.+)//.+', '%1'))