-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.lua
45 lines (39 loc) · 947 Bytes
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local __dir__ = hs.spoons.scriptPath()
local knu = {
name = "Knu",
version = "1.0.0",
author = "Akinori Musha <[email protected]>",
homepage = "https://github.com/knu/hs-knu",
license = "BSD-2-Clause - https://opensource.org/licenses/BSD-2-Clause",
}
local function loadModule(name)
knu[name] = dofile(hs.spoons.resourcePath(name .. ".lua"))
return knu[name]
end
setmetatable(knu, {
-- Autoload
__index = function (self, name)
if name ~= "init" then
return loadModule(name)
end
end
})
-- Preloads all or some submodules
knu.preload = function (...)
local modules = {...}
if #modules == 0 then
-- Load all files
for file in hs.fs.dir(__dir__) do
local name = file:match("^([^.]+)%.lua$")
if name and name ~= "init" then
return loadModule(name)
end
end
else
for _, name in modules do
loadModule(name)
end
end
return true
end
return knu