Now standalone plugin
First impl of standalone colorscheme
This commit is contained in:
36
lua/astrobox/utils.lua
Normal file
36
lua/astrobox/utils.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
local function get_module_root_path(modname)
|
||||
local list = vim.loader.find(modname)
|
||||
if list and #list then
|
||||
return list[1].modpath:sub(0, -9) -- Cut init.lua
|
||||
end
|
||||
end
|
||||
|
||||
ASTROBOX_ROOT_PATH = get_module_root_path("astrobox")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.visit_astrobox_modules(module, visitor)
|
||||
local modpath = ASTROBOX_ROOT_PATH .. module:gsub("%.", "/")
|
||||
local hdl, err, msg = vim.loop.fs_scandir(modpath)
|
||||
if hdl == nil then
|
||||
print("Astrobox err: " .. err .. " " .. vim.inspect(msg))
|
||||
return
|
||||
end
|
||||
while true do
|
||||
local entry, type = vim.loop.fs_scandir_next(hdl)
|
||||
if entry == nil then
|
||||
break
|
||||
end
|
||||
if type == "file" and vim.endswith(entry, ".lua") then
|
||||
local mod_name = entry:sub(0, -5) -- cut extension
|
||||
local ok, mod = pcall(require, "astrobox." .. module .. "." .. mod_name)
|
||||
if ok then
|
||||
visitor(mod, mod_name)
|
||||
else
|
||||
print("AstroBox:Failed to load module " .. mod_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user