-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
174 lines (150 loc) · 3.61 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
-- local menubar = hs.menubar.new()
-- menubar:setIcon("flash.pdf")
-- menubar:setMenu({
-- { title = "Reload", fn = hs.reload },
-- { title = "Console", fn = hs.openConsole },
-- })
local hyper = {"alt", "ctrl"}
-- undo
local undo = require 'undo'
hs.hotkey.bind(hyper, 'u', function()
undo:undo()
end)
-- Maximize
hs.hotkey.bind(hyper, "o", function ()
-- hs.grid.maximizeWindow()
local win = hs.window.focusedWindow()
if not win or win:isFullScreen() then
return
end
undo:addToStack()
win:maximize()
end)
-- left half
hs.hotkey.bind(hyper, "left", function()
local win = hs.window.focusedWindow()
if not win or win:isFullScreen() then
return
end
local screenrect = win:screen():frame()
local f = win:frame()
f.x = 0
f.y = 0
f.w = screenrect.w / 2
f.h = screenrect.h
undo:addToStack()
win:setFrame(f)
end)
-- right half
hs.hotkey.bind(hyper, "right", function()
local win = hs.window.focusedWindow()
if not win or win:isFullScreen() then
return
end
local screenrect = win:screen():frame()
local f = win:frame()
f.x = screenrect.w / 2
f.y = 0
f.w = screenrect.w / 2
f.h = screenrect.h
undo:addToStack()
win:setFrame(f)
end)
-- top half
hs.hotkey.bind(hyper, "up", function ()
local win = hs.window.focusedWindow()
if not win or win:isFullScreen() then
return
end
local screenrect = win:screen():frame()
local f = win:frame()
f.x = 0
f.y = 0
f.w = screenrect.w
f.h = screenrect.h / 2
undo:addToStack()
win:setFrame(f)
end)
-- below half
hs.hotkey.bind(hyper, "down", function()
local win = hs.window.focusedWindow()
if not win or win:isFullScreen() then
return
end
local screenrect = win:screen():frame()
local f = win:frame()
f.x = 0
f.y = screenrect.h / 2 + 23
f.w = screenrect.w
f.h = screenrect.h / 2
undo:addToStack()
win:setFrame(f)
end)
local apps = {
q = 'QQ',
g = "Google Chrome",
k = "Slack",
--i = "iTerm"
--e = "Emacs",
w = "WeChat",
t = "Telegram"
}
apps["1"] = "1Password"
for key, name in pairs(apps) do
hs.hotkey.bind(hyper, key, function()
hs.application.launchOrFocus(name)
moveCursorToWindowCenter()
end)
end
hs.hints.showTitleThresh = 0
hs.hotkey.bind(hyper, "l", function()
local qq = hs.appfinder.appFromName("QQ")
hs.hints.windowHints(table.insert({}, qq))
end)
function moveCursorToWindowCenter()
local win = hs.window.focusedWindow()
local f = win:frame()
hs.mouse.setAbsolutePosition({
x = f.x + f.w / 2,
y = f.y + f.h / 2,
})
end
hs.hotkey.bind(hyper, "0", function()
local apps = {
{ name = 'Slack', x = 959, y = 0, w = 959, h = 1150 },
{ name = 'Telegram', x = 0, y = 465, w = 959, h = 590 },
--{ name = 'WeChat', x = 0, y = 650, w = 1080, h = 600 },
{ name = 'QQ', x = 0, y = 0, w = 959, h = 560 },
}
for _, app in pairs(apps) do
local a = hs.appfinder.appFromName(app.name)
if a ~= nil then
local w = a:mainWindow()
local f = w:frame()
f.x = app.x
f.y = app.y
f.w = app.w
f.h = app.h
w:setFrame(f)
end
end
end)
hs.hotkey.bind(hyper, "e", function()
local app = hs.appfinder.appFromName("Emacs")
if app == nil then return end
app:activate()
moveCursorToWindowCenter()
end)
function reloadConfig(files)
doReload = false
for _,file in pairs(files) do
if file:sub(-4) == ".lua" then
doReload = true
end
end
if doReload then
hs.reload()
end
end
hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
hs.alert.show("Config loaded")