feat: Add custom scripts and hook based setup
This commit introduces a hook system that allows the user to add custom modules which can use these hooks to invoke function af specific NvChad events to allow for extending og functionalitynavigator
parent
ca1ad15ad2
commit
bfc10e6034
@ -0,0 +1,22 @@
|
||||
local function isModuleAvailable(name)
|
||||
if package.loaded[name] then
|
||||
return true
|
||||
else
|
||||
for _, searcher in ipairs(package.searchers or package.loaders) do
|
||||
local loader = searcher(name)
|
||||
if type(loader) == 'function' then
|
||||
package.preload[name] = loader
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local loadIfExists = function (module)
|
||||
if isModuleAvailable(module) then
|
||||
require(module)
|
||||
end
|
||||
end
|
||||
|
||||
loadIfExists('custom')
|
@ -0,0 +1,38 @@
|
||||
local hooks, M = {}, {};
|
||||
local allowed_hooks = {
|
||||
"install_plugins",
|
||||
"setup_mappings",
|
||||
"ready",
|
||||
}
|
||||
|
||||
local function has_value (tab, val)
|
||||
for _, value in ipairs(tab) do
|
||||
if value == val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
M.add = function(name, fn)
|
||||
if not(has_value(allowed_hooks, name)) then
|
||||
error("Custom lua uses unallowed hook " .. name)
|
||||
end
|
||||
if hooks[name] == nil then
|
||||
hooks[name] = {}
|
||||
end
|
||||
table.insert(hooks[name], fn);
|
||||
end
|
||||
|
||||
M.run = function(name, args)
|
||||
if hooks[name] == nil then
|
||||
return;
|
||||
end
|
||||
|
||||
for _, hook in pairs(hooks[name]) do
|
||||
hook(args)
|
||||
end
|
||||
end
|
||||
|
||||
return M;
|
@ -0,0 +1,2 @@
|
||||
-- This is where you custom modules and plugins goes.
|
||||
-- See the wiki for a guide on how to extend NvChad
|
Loading…
Reference in New Issue