-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinit.lua
80 lines (67 loc) · 1.88 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local LOGLEVEL = 'debug'
-- List of modules to load (found in modules/ dir)
local modules = {
'appwindows',
'browser',
'caffeine',
'cheatsheet',
-- Do not use hazel module without configuring the Dump folder or you could
-- lose data!
-- 'hazel',
'notational',
'scratchpad',
'songs',
'timer',
'weather',
'wifi',
'worktime',
}
-- global modules namespace (short for easy console use)
hsm = {}
-- load module configuration
local cfg = require('config')
hsm.cfg = cfg.global
-- global log
hsm.log = hs.logger.new(hs.host.localizedName(), LOGLEVEL)
-- load a module from modules/ dir, and set up a logger for it
local function loadModuleByName(modName)
hsm[modName] = require('modules.' .. modName)
hsm[modName].name = modName
hsm[modName].log = hs.logger.new(modName, LOGLEVEL)
hsm.log.i(hsm[modName].name .. ': module loaded')
end
-- save the configuration of a module in the module object
local function configModule(mod)
mod.cfg = mod.cfg or {}
if (cfg[mod.name]) then
for k,v in pairs(cfg[mod.name]) do mod.cfg[k] = v end
hsm.log.i(mod.name .. ': module configured')
end
end
-- start a module
local function startModule(mod)
if mod.start == nil then return end
mod.start()
hsm.log.i(mod.name .. ': module started')
end
-- stop a module
local function stopModule(mod)
if mod.stop == nil then return end
mod.stop()
hsm.log.i(mod.name .. ': module stopped')
end
-- load, configure, and start each module
hs.fnutils.each(modules, loadModuleByName)
hs.fnutils.each(hsm, configModule)
hs.fnutils.each(hsm, startModule)
-- global function to stop modules and reload hammerspoon config
function hs_reload()
hs.fnutils.each(hsm, stopModule)
hs.reload()
end
-- load and bind key bindings
local bindings = require('bindings')
bindings.bind()
-- Disable all window animations
hs.window.animationDuration = 0
hs.alert.show('Hammerspoon Config Loaded', 1)