-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
116 lines (86 loc) · 3.62 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
-- init.lua -- hammerspoon controller
-- luacheck: globals hs load_module load_config mod ins cfg notify cls
require "utils"
hs.logger.defaultLogLevel = "info"
local log = hs.logger.new("init")
cfg = load_config()
local function local_modules(mod, modifiers)
-- some modules that I've yet to turn into spoons
mod.bindings = load_module("bindings") -- ModalMgr set up and miscellaneous key bindings
mod.bindings.init(modifiers, cfg.script_config['bindings'])
mod.passwords = load_module("passwords") -- Passwords from Keychain at a key press
mod.passwords.init(modifiers)
mod.sleepwatcher = load_module("sleepwatcher") -- Act on sleep/wake events
mod.sleepwatcher.init()
mod.webviews = load_module("webviews") -- Web page browsers and related key bindings
mod.webviews.init(modifiers)
mod.wifi = load_module("wifi") -- Watch for Wifi changes, toggle network location
mod.wifi.init(modifiers)
mod.switcher = load_module("switcher") -- Raise on activation and other macOS UI tweaks
mod.switcher.init(modifiers)
end
local function spoon_wrappers(mod, modifiers)
-- Configure and load official Spoons - https://github.com/Hammerspoon/Spoons
mod.usb = load_module("usb") -- Watch for USB events
mod.usb.init(modifiers)
mod.tm_progress = load_module("tm_progress") -- TimeMachineProgress
mod.tm_progress = mod.tm_progress.init("info", false)
mod.window_mgr = load_module("window_mgr") -- Window management
mod.window_mgr.init(modifiers, cfg.script_config['window_mgr'])
mod.caffeine = load_module("caffeine") -- Caffeine/caffeinate replacement
mod.caffeine.init(modifiers)
mod.ksheet = load_module("ksheet") -- Cheatsheet replacement
mod.ksheet.init(modifiers, cfg.script_config['ksheet'])
end
local function work_config(mod, modifiers)
local this_host = hs.host.localizedName()
-- Work specific initialization
if cfg.work then
if not ( this_host == cfg.hostname or this_host == cfg.work.hostname ) then
notify("Hostname " .. this_host .. " not recognized for work config", 0)
elseif this_host == cfg.work.hostname then
mod.log.i("\n%s\nInitializing work functions", string.rep('_', 50))
mod.work = cfg.work.init(modifiers, cfg.work.defs)
mod.log.vf("work init returned %s", hs.inspect(mod.work))
else
mod.log.f("No work functions for host %s, unloading.", cfg.hostname)
cfg.work = nil
end
end
end
local function watch_config(mod)
-- Finally, a watcher for when any of this changes
-- ToDo Is there a way to just check a list of required scripts?
mod.autoreloader = load_module("auto_reload") -- Watch for config file changes
mod.autoreloader.init()
end
local function hammerspoon_tweaks(mod)
-- Aspects related to overall Hammerspoon operation
load_module("hs.ipc") -- enable Hammerspoon access from the command line
if not hs.loadSpoon("EmmyLua") then -- Set up VSCodium Hammerspoon extension integration
log.ef("You'll need to install %s for VSCodium/VS Code extension integration",
"https://www.hammerspoon.org/Spoons/EmmyLua.html")
end
if mod.log.level < 4 then
hs.console.clearConsole()
else
-- debug or greater leave console as is, except add convenience aliase
cls = hs.console.setConsole
end
end
local function init()
-- Driver for the remainder of configuration
log.i("Started")
mod = {}
mod.log = log
mod.log.setLogLevel(cfg.log_level)
load_module("utils")
ins = hs.inspect -- console convenience function
local modifiers = cfg.hyper or "alt"
local_modules(mod, modifiers)
spoon_wrappers(mod, modifiers)
work_config(mod, modifiers)
hammerspoon_tweaks(mod)
watch_config(mod)
end
init()