-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
297 lines (236 loc) · 8.2 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
-- hs.logger.defaultLogLevel = "info"
-- Logger setup
require("functions")
hs.logger.setGlobalLogLevel("debug")
-- hs.logger.defaultLogLevel = 'warning'
logger = hs.logger.new("Init", "debug")
hs.console.clearConsole()
package.path = package.path .. ";" .. "/Users/jiya/.luarocks/share/lua/5.3/?.lua"
package.cpath = package.cpath .. ";" .. "/Users/jiya/.config/yarn/bin/lib/lua/5.1/?.so"
-- local clocking = require 'clocking'
-- clocking.init()
function isArm64Func()
local out = hs.execute("uname -m")
if out then
out = string.gsub(out, "^%s*(.-)%s*$", "%1")
return out == "arm64"
end
return false
end
isArm64 = isArm64Func()
logger:d("isArm64 is:" .. tostring(isArm64 or "false"))
require("app.app"):start()
-- Hotkey definitions
local HYPER = {"ctrl", "alt", "cmd", "shift"}
local HYPER_MINUS_SHIFT = {"ctrl", "alt", "cmd"}
-- Bug-fixed Spoon that handles modal key bindings
hs.loadSpoon("ModalMgr")
-- Modified Spoon that manages modal state and UI.
hs.loadSpoon("MiroWindowsManager")
keyUpDown = function(modifiers, key)
-- Un-comment & reload config to log each keystroke that we're triggering
-- self.logger:d('Sending keystroke:', hs.inspect(modifiers), key)
hs.eventtap.keyStroke(modifiers, key, 0)
end
-- Subscribe to the necessary events on the given window filter such that the
-- given hotkey is enabled for windows that match the window filter and disabled
-- for windows that don't match the window filter.
--
-- windowFilter - An hs.window.filter object describing the windows for which
-- the hotkey should be enabled.
-- hotkey - The hs.hotkey object to enable/disable.
--
-- Returns nothing.
enableHotkeyForWindowsMatchingFilter = function(windowFilter, hotkey)
windowFilter:subscribe(hs.window.filter.windowFocused, function() hotkey:enable() end)
windowFilter:subscribe(hs.window.filter.windowUnfocused, function() hotkey:disable() end)
end
-- local zmc = hs.loadSpoon('zmc')
-- local ModalWrapper = require 'modal-wrapper'
-- windowHighlight = require("windowHighlight").start()
require("applicationWatcher"):start()
hs.hints.style = "vimperator"
-- local window = require 'hs.window'
local alert = require("hs.alert")
local application = require("hs.application")
local geometry = require("hs.geometry")
local grid = require("hs.grid")
local hints = require("hs.hints")
local hotkey = require("hs.hotkey")
local layout = require("hs.layout")
local window = require("hs.window")
local speech = require("hs.speech")
-- Misc configs
hs.autoLaunch(true)
hs.automaticallyCheckForUpdates(true)
hs.preferencesDarkMode(true)
hs.accessibilityState(true) -- show System Preferences if Accessibility is not enabled for Hammerspoon
hs.dockIcon(false)
hs.menuIcon(true)
hs.consoleOnTop(true)
hs.uploadCrashData(false)
local caffeine = hs.loadSpoon("Caffeine")
caffeine:bindHotkeys({toggle = {HYPER, "C"}})
caffeine:start()
-- -- caffeine default on
-- caffeine:clicked()
-- hs.loadSpoon('ControlEscape'):start() -- Load Hammerspoon bits from https://github.com/jasonrudolph/ControlEscape.spoon"
-- ---------------
-- Global Bindings
-- ---------------
-- local seal = hs.loadSpoon('Seal')
-- seal:loadPlugins({
-- "apps", "useractions", 'tunnelblick', 'network_locations', -- 'snippets',
-- 'macos', 'hammerspoon'
-- })
-- -- seal:bindHotkeys({toggle = {HYPER, 'space'}})
-- -- local seal = spoon.Seal
-- seal.plugins.useractions.actions = {
-- ["rebootmac"] = {
-- fn = hs.caffeinate.restartSystem,
-- -- hotkey = { hyper2, "r" },
-- keyword = "restart"
-- -- icon = swisscom_logo,
-- },
-- ["shutdownmac"] = {
-- fn = hs.caffeinate.shutdownSystem,
-- -- hotkey = { hyper2, "r" },
-- keyword = "shutdown"
-- },
-- ["haltmac"] = {
-- fn = hs.caffeinate.shutdownSystem,
-- -- hotkey = { hyper2, "r" },
-- keyword = "halt"
-- },
-- ["lockmac"] = {
-- fn = hs.caffeinate.lockScreen,
-- -- hotkey = { hyper2, "r" },
-- keyword = "lock"
-- }
-- }
-- seal:refreshAllCommands()
-- seal:start()
-- Disable window size transition animations
hs.window.animationDuration = 0.3
-- Install:andUse(
-- "MiroWindowsManager",
-- {
-- hotkeys = {
-- up = {HYPER, "k"},
-- right = {HYPER, "l"},
-- down = {HYPER, "j"},
-- left = {HYPER, "h"},
-- fullscreen = {HYPER, "m"}
-- }
-- }
-- )
-- Install:andUse(
-- "TextClipboardHistory",
-- {
-- config = {show_in_menubar = false},
-- hotkeys = {toggle_clipboard = {HYPER, "v"}},
-- start = true
-- }
-- )
-- Power JSON Editor cmd-t work as new tab
newTabWithPowerJSONEditor = hs.hotkey.new("cmd", "t", function()
hs.application.launchOrFocusByBundleID("com.xujiwei.powerjsoneditor")
-- newTabWithPowerJSONEditor:disable() -- does not work without this, even though it should
-- hs.eventtap.keyStroke({"cmd"}, "t")
local topWindow = hs.window:frontmostWindow()
if topWindow ~= nil then
local topApp = topWindow:application()
if topApp ~= nil then
local bunderID = topApp:bundleID()
if bunderID == "com.xujiwei.powerjsoneditor" then
local newTabAppleScriptFile = hs.configdir ..
"/applescript/powerjsoneditor_newtab.applescript"
hs.osascript.applescriptFromFile(newTabAppleScriptFile)
end
end
end
end)
hs.window.filter.new("Power JSON Editor"):subscribe(hs.window.filter.windowFocused, function()
newTabWithPowerJSONEditor:enable()
end):subscribe(hs.window.filter.windowUnfocused, function() newTabWithPowerJSONEditor:disable() end)
local clock = hs.loadSpoon("AClock")
clock.format = "%H:%M:%S"
clock.textColor = {hex = "#00c403"}
clock.textFont = "Menlo Bold"
clock.height = 160
clock.width = 675
clock:init()
-- hs.inspect(spoon.Clocking)
hs.loadSpoon("Clocking"):start()
hs.loadSpoon("TimeMachineProgress"):start()
local utils = require("utils")
local wifi = require("wifi")
hs.hotkey.alertDuration = 0
hs.application.enableSpotlightForNameSearches(true)
--
-- Turn off Animations.
--
hs.window.animationDuration = 0
-- And now for hotkeys relating to Hyper. First, let's capture all of the functions, then we can just quickly iterate and bind them
local hyperfns = {}
hyperfns["L"] = hs.caffeinate.lockScreen
hyperfns["R"] = hs.reload
-- -- Increase / decrease flux intensity.
-- hyperfns[','] = flux.decreaseLevel
-- hyperfns['.'] = flux.increaseLevel
-- -- Lock System
-- switch
hyperfns["-"] = wifi.toggleWifi
-- hyperfns['t'] = require("blj.blj")
for _hotkey, _fn in pairs(hyperfns) do hs.hotkey.bind(HYPER, _hotkey, _fn) end
-- Display Hammerspoon logo
hs.loadSpoon("FadeLogo")
spoon.FadeLogo.zoom = false
spoon.FadeLogo.image_size = hs.geometry.size(80, 80)
spoon.FadeLogo.run_time = 1.5
spoon.FadeLogo:start()
-- For debug
local function showKeyPress(tapEvent)
local charactor = hs.keycodes.map[tapEvent:getKeyCode()]
hs.alert.show(charactor, 1.5)
end
local keyTap = hs.eventtap.new({hs.eventtap.event.types.keyDown}, showKeyPress)
k = hs.hotkey.modal.new({"cmd", "shift", "ctrl"}, "P")
function k:entered()
hs.alert.show("Enabling Keypress Show Mode", 1.5)
keyTap:start()
end
function k:exited() hs.alert.show("Disabling Keypress Show Mode", 1.5) end
k:bind({"cmd", "shift", "ctrl"}, "P", function()
keyTap:stop()
k:exit()
end)
local crypto = require("work/crypto")
crypto:start()
local mail = require("work/mail")
mail:start()
local notify = require("notify")
notify:start()
-- local convert_trans = require('my/convert_trans')
-- convert_trans:start()
-- debug only
-- log all window
-- local allWindows = hs.window.allWindows()
-- if allWindows then
-- for _, w in ipairs(allWindows) do
-- -- logger:d('title: ', w:title())
-- local app = w:application()
-- if app then
-- local bundleID = app:bundleID()
-- logger:d('title:', w:title(), ', bundleID:', bundleID, ', app name:', app:name())
-- end
-- end
-- end
-- -- debug
-- local osStr = hs.host.operatingSystemVersionString()
-- logger:d("os str: " .. (osStr or 'nil'))
-- local hostNames = hs.host.names()
-- logger:d("hostNames: " .. hs.json.encode(hostNames, true))
require("window"):start()
-- local usb = require("usb")
-- usb:start()