From 2bace8525ab30d08273b986622e1add755febc44 Mon Sep 17 00:00:00 2001 From: David Ibia Date: Sun, 3 Mar 2024 12:02:38 +0100 Subject: [PATCH] feat(get-git-root.lua): add Lua function to get the root directory of a Git project using 'git rev-parse --show-toplevel' command --- lua/absolute/utils/get-git-root.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lua/absolute/utils/get-git-root.lua diff --git a/lua/absolute/utils/get-git-root.lua b/lua/absolute/utils/get-git-root.lua new file mode 100644 index 0000000..9748c64 --- /dev/null +++ b/lua/absolute/utils/get-git-root.lua @@ -0,0 +1,10 @@ +function GetProjectRoot() + local git_root = vim.fn.systemlist("git rev-parse --show-toplevel")[1] + if git_root == nil then + return vim.fn.getcwd() + else + return git_root + end +end + +return GetProjectRoot