local plugins_dir = vim.fn.stdpath('config') .. '/lua/plugins'
|
|
local plugin_files = vim.fn.globpath(plugins_dir, '*.lua', false, true)
|
|
|
|
local plugins_to_add = {}
|
|
local plugins_to_setup = {}
|
|
|
|
-- Collect all plugin configs (excluding init.lua)
|
|
for _, file in ipairs(plugin_files) do
|
|
local filename = vim.fn.fnamemodify(file, ':t:r')
|
|
|
|
if filename ~= 'init' then
|
|
local ok, plugin = pcall(require, 'plugins.' .. filename)
|
|
|
|
if ok and type(plugin) == 'table' then
|
|
if not plugin.disabled then
|
|
if plugin.install then
|
|
table.insert(plugins_to_add, plugin.install)
|
|
end
|
|
|
|
if plugin.dependencies then
|
|
vim.list_extend(
|
|
plugins_to_add,
|
|
plugin.dependencies
|
|
)
|
|
end
|
|
|
|
if plugin.setup and type(plugin.setup) == 'function' then
|
|
table.insert(plugins_to_setup, {
|
|
name = filename,
|
|
setup = plugin.setup
|
|
})
|
|
end
|
|
end
|
|
else
|
|
vim.notify('Failed to load plugin: ' .. filename .. ': ' .. tostring(plugin), vim.log.levels.WARN)
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Add all plugins
|
|
vim.pack.add(plugins_to_add)
|
|
|
|
-- Run all setup functions
|
|
for _, plugin in ipairs(plugins_to_setup) do
|
|
local ok, err = pcall(plugin.setup)
|
|
if not ok then
|
|
vim.notify('Failed to setup plugin ' .. plugin.name .. ': ' .. tostring(err), vim.log.levels.ERROR)
|
|
end
|
|
end
|