nvim: Only load plugin spec if plugin files exist

Before we load the lazy spec from the 'lua/plugins' directory, we check
that the directory exists and contains at least one .lua file. We do not
check that the file returns a valid spec but that is just assumed in
this case.
This commit is contained in:
Marty Oehme 2024-08-15 08:23:16 +02:00
parent 3e369ee31e
commit f8625f35f0
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -31,8 +31,13 @@ if not vim.loop.fs_stat(lazypath) then
end
vim.opt.rtp:prepend(lazypath)
-- ensure plugins specs exist before loading into lazy
local spec_dir = vim.fn.stdpath("config") .. "/lua/plugins"
local spec_exist = (vim.fn.isdirectory(spec_dir) ~= 0) and (#vim.fn.glob(spec_dir .. "/*.lua", nil, true) ~= 0)
local spec = spec_exist and { import = "plugins" } or {}
require("lazy").setup({
spec = { { import = "plugins" } },
spec = { spec },
defaults = { lazy = true, version = "*" },
performance = {
rtp = { disabled_plugins = { "netrw", "netrwPlugin" } },