Only auto add projects if there is a root directory that matches the pattern for a project

master
Bryan 2024-09-16 23:40:19 -06:00
parent 320c2bcd10
commit 29f7169490
2 changed files with 7 additions and 2 deletions

View File

@ -3,13 +3,16 @@ local repo = require("cd-project.project-repo")
local utils = require("cd-project.utils")
---@return string|nil
local function find_project_dir()
local function find_project_dir(auto)
local found = vim.fs.find(
vim.g.cd_project_config.project_dir_pattern,
{ upward = true, stop = vim.loop.os_homedir(), path = vim.fs.dirname(vim.fn.expand("%:p")) }
)
if #found == 0 then
if auto then
return nil
end
-- if there are no parent directories matching the project pattern then use current directory as project directory
return vim.fn.getcwd()
end

View File

@ -6,7 +6,9 @@ local function setup()
vim.api.nvim_create_autocmd({ "VimEnter" }, {
group = auto_group_name,
callback = function(_)
api.add_current_project({ show_duplicate_hints = false })
if api.find_project_dir(true) ~ nil then
api.add_current_project({ show_duplicate_hints = false })
end
end,
})
end