diff options
| author | Sebastian Lara Menares <slara@mtsolutions.io> | 2023-11-06 22:29:05 -0300 |
|---|---|---|
| committer | Sebastian Lara Menares <slara@mtsolutions.io> | 2023-11-06 22:29:05 -0300 |
| commit | ab0420b8dc27bee49f7791a7b8d0500ef970b3d7 (patch) | |
| tree | 78b5c74e0d602055d76ddd3d4788fa51d287cf2b | |
| parent | 595165e39195e53348054c0a4e715a2e98a82805 (diff) | |
| download | dots-ab0420b8dc27bee49f7791a7b8d0500ef970b3d7.tar.gz | |
Live Grep from Git root falls back to cwd on special buffers
| -rw-r--r-- | nvim/init.lua | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/nvim/init.lua b/nvim/init.lua index b4b8305..0976a46 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -313,18 +313,21 @@ pcall(require('telescope').load_extension, 'fzf') local function find_git_root() -- Use the current buffer's path as the starting point for the git search local current_file = vim.api.nvim_buf_get_name(0) + local current_dir + local cwd = vim.fn.getcwd() -- If the buffer is not associated with a file, return nil if current_file == "" then - print("Buffer is not associated with a file") - return nil + current_dir = cwd + else + -- Extract the directory from the current file's path + current_dir = vim.fn.fnamemodify(current_file, ":h") end - -- Extract the directory from the current file's path - local current_dir = vim.fn.fnamemodify(current_file, ":h") + -- Find the Git root directory from the current file's path local git_root = vim.fn.systemlist("git -C " .. vim.fn.escape(current_dir, " ") .. " rev-parse --show-toplevel")[1] if vim.v.shell_error ~= 0 then - print("Not a git repository") - return nil + print("Not a git repository. Searching on current working directory") + return cwd end return git_root end |