mirror of
https://github.com/Baipyrus/nvim-config.git
synced 2024-11-09 03:03:50 +00:00
Merge pull request #494 from slara/master
This commit is contained in:
commit
47974f7db1
15
init.lua
15
init.lua
@ -313,18 +313,21 @@ pcall(require('telescope').load_extension, 'fzf')
|
|||||||
local function find_git_root()
|
local function find_git_root()
|
||||||
-- Use the current buffer's path as the starting point for the git search
|
-- 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_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 the buffer is not associated with a file, return nil
|
||||||
if current_file == "" then
|
if current_file == "" then
|
||||||
print("Buffer is not associated with a file")
|
current_dir = cwd
|
||||||
return nil
|
else
|
||||||
end
|
|
||||||
-- Extract the directory from the current file's path
|
-- Extract the directory from the current file's path
|
||||||
local current_dir = vim.fn.fnamemodify(current_file, ":h")
|
current_dir = vim.fn.fnamemodify(current_file, ":h")
|
||||||
|
end
|
||||||
|
|
||||||
-- Find the Git root directory from the current file's path
|
-- 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]
|
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
|
if vim.v.shell_error ~= 0 then
|
||||||
print("Not a git repository")
|
print("Not a git repository. Searching on current working directory")
|
||||||
return nil
|
return cwd
|
||||||
end
|
end
|
||||||
return git_root
|
return git_root
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user