local pluginsMod = "tjk.plugins" -- module containing plugin modules -- fancy plugin loader function require_plugin(moduleName, source, setup, loadFn) local ok, mod = pcall(require, moduleName) if not ok then if not source then vim.notify("Failed to load plugin module without source " .. moduleName, vim.log.levels.ERROR) return end vim.pack.add { source } ok, mod = pcall(require, moduleName) if not ok then vim.notify(mod, vim.log.levels.ERROR) return end end if setup and mod.setup then mod.setup(setup == true and {} or setup) end if loadFn then loadFn() end end -- helper for handling dependencies and parsing module function require_plugin_from_module(mod) -- mod == true means it returned nothing if mod == true or mod.enabled == false then return end for _, dMod in ipairs(mod.dependencies or {}) do require_plugin_from_module(dMod) end require_plugin(mod.moduleName or mod[1], mod.source or mod[2], mod.setup, mod.loadFn) for _, dMod in ipairs(mod.dependents or {}) do require_plugin_from_module(dMod) end end -- loop over plugins local pluginsPath = vim.fn.stdpath("config") .. "/lua/" .. pluginsMod:gsub("%.", "/") for _, f in ipairs(vim.fn.glob(pluginsPath .. "/*.lua", false, true)) do local name = vim.fn.fnamemodify(f, ":t:r") local modName = pluginsMod .. "." .. name require_plugin_from_module(require(modName)) end