-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
437 lines (370 loc) · 11.3 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
-- Requires, this could easily add pretty advanced packages
-- inspect = require 'inspect'
-- Current application hotkeys set
-- 'G', openbrowser
-- 'R', openrdp
-- 'I', openemail
-- 'Q', openqtcreator
-- 'V', openvim
-- 'D', openterminal
-- 'E', find something new for openatom
-- 'E', opengimp
-- 'H', opentortoise
-- 'M', openmusicplayer
-- 'J', openchatprogram
-- 'P', openpgadmin
-- 'O', openmail
-- 'N', openfinder
-- 'L', openlaunchpad
-- 'K', openkitematic
local grid = require "hs.grid"
local hotkey = require "hs.hotkey"
--------------------------------------------------------------------------------
-- CONSTANTS
--------------------------------------------------------------------------------
local cmd_alt = {"cmd", "alt"}
local cmd_shift = {"cmd", "shift"}
local ctrl_alt = {"ctrl", "alt"}
local hyper = {"cmd", "alt", "ctrl"}
local easykey = {"cmd", "ctrl"}
local yay = "ᕙ(⇀‸↼‶)ᕗ reloaded"
hotkey.bind(cmd_alt, 'N', grid.pushWindowNextScreen)
hotkey.bind(cmd_alt, 'P', grid.pushWindowPrevScreen)
--------------------------------------------------------------------------------
-- RELOAD
--------------------------------------------------------------------------------
hotkey.bind(hyper, "C", function()
hs.reload()
--hs.alert("Reloaded ^_^")
-- hs.alert(yay) -- I do not know why these won't print to the screen
-- but I've added a hs.alert(yay) to the bottom and it will do the job
end)
--------------------------------------------------------------------------------
-- WINDOW HINTS
--------------------------------------------------------------------------------
hotkey.bind({"ctrl"},";",hs.hints.windowHints)
--------------------------------------------------------------------------------
-- OPEN CONSOLE
--------------------------------------------------------------------------------
hotkey.bind(hyper, "X", function()
hs.openConsole()
hs.focus()
end)
--------------------------------------------------------------------------------
-- CHANGE FOCUS
--------------------------------------------------------------------------------
-- hotkey.bind({"ctrl"}, "L", function()
-- local win = hs.window.focusedWindow()
-- win:focusWindowEast()
-- local f = win:frame()
-- -- make it so that I can move the mouse to the center of this window
-- -- local screen = win:screen()
-- -- local max = screen:frame()
-- -- local a = {}
-- -- a.x = max.x / 2 -- this isn't good but it does move the mouse
-- -- a.y = max.y / 2
-- -- hs.mouse.setAbsolutePosition(a)
-- end)
--
-- hotkey.bind({"ctrl"}, "H", function()
-- local win = hs.window.focusedWindow()
-- win:focusWindowWest()
-- end)
--
-- hotkey.bind({"ctrl"}, "K", function()
-- local win = hs.window.focusedWindow()
-- win:focusWindowNorth()
-- end)
--
-- hotkey.bind({"ctrl"}, "J", function()
-- local win = hs.window.focusedWindow()
-- win:focusWindowSouth()
-- end)
--------------------------------------------------------------------------------
-- WINDOW MOVEMENT
--------------------------------------------------------------------------------
hotkey.bind(hyper, "M", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end)
hotkey.bind(hyper, "N", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
-- local max = screen:frame()
f.x = 223
f.y = 196
f.w = 1467
f.h = 696
win:setFrame(f)
end)
hotkey.bind(hyper, "Down", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y + (max.h / 2)
f.w = max.w
f.h = max.h / 2
win:setFrame(f)
end)
hotkey.bind(hyper, "Up", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h / 2 + 9
win:setFrame(f)
end)
hotkey.bind(hyper, "Left", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
hotkey.bind(hyper, "Right", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
local laptopScreen = "Color LCD"
local windowLayout = {
{"Google Chrome", nil, laptopScreen, hs.layout.left50, nil, nil},
{"MacVim", nil, laptopScreen, hs.layout.right50, nil, nil},
{"iTunes", "iTunes", laptopScreen, hs.layout.maximized, nil, nil},
{"iTunes", "MiniPlayer", laptopScreen, nil, nil, hs.geometry.rect(0, -48, 400, 48)},
}
-- > for _, i in pairs(hs.screen.allScreens()) do print(i:id()) end :: this was the command and it returned those two ids which will probbaly come in handy
-- something like hs.screen(47821613) will find the left monitor
-- 478216137
-- 478215722
-- hs.layout.apply(windowLayout)
-- EXTRA :) -- These are really good CHROME/DEVTOOLS
hotkey.bind(cmd_alt, "H", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w * 7 / 12
f.h = max.h
win:setFrame(f)
end)
hotkey.bind(cmd_alt, "L", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w * 7 / 12)
f.y = max.y
f.w = max.w * 5 / 12
f.h = max.h
win:setFrame(f)
end)
hotkey.bind(cmd_alt, "K", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h * 3 / 4
win:setFrame(f)
end)
--------------------------------------------------------------------------------
-- Creating a simple menubar item
--------------------------------------------------------------------------------
local caffeine = hs.menubar.new()
function setCaffeineDisplay(state)
if state then
caffeine:setTitle("AWAKE")
else
caffeine:setTitle("SLEEPY")
end
end
function caffeineClicked()
setCaffeineDisplay(hs.caffeinate.toggle("displayIdle"))
end
if caffeine then
caffeine:setClickCallback(caffeineClicked)
setCaffeineDisplay(hs.caffeinate.get("displayIdle"))
end
--------------------------------------------------------------------------------
-- APPLICATION FOCUS MOVEMENT
--------------------------------------------------------------------------------
local function opengimp()
hs.application.launchOrFocus("Gimp")
end
local function openrdp()
hs.application.launchOrFocus("Microsoft Remote Desktop")
end
local function openbrowser()
hs.application.launchOrFocus("Firefox")
end
local function openterminal()
hs.application.launchOrFocus("iTerm")
end
local function openatom()
hs.application.launchOrFocus("Visual Studio Code")
end
local function opentortoise()
hs.application.launchOrFocus("TortoiseHg")
end
local function openmusicplayer()
hs.application.launchOrFocus("Spotify")
end
local function openchatprogram()
hs.application.launchOrFocus("Slack")
end
local function openvim()
hs.application.launchOrFocus("MacVim")
end
local function openqtcreator()
hs.application.launchOrFocus("Qt Creator")
end
local function openemail()
hs.application.launchOrFocus("Mail")
end
local function openpgadmin()
hs.application.launchOrFocus("pgAdmin 4")
end
local function openmail()
hs.application.launchOrFocus("Mail")
end
local function openfinder()
hs.application.launchOrFocus("Finder")
end
local function openlaunchpad()
hs.application.launchOrFocus("Launchpad")
end
local function openkitematic()
hs.application.launchOrFocus("Docker")
end
local function opencalendar()
hs.application.launchOrFocus("Calendar")
end
local function openzoom()
hs.application.launchOrFocus("zoom.us")
end
local function opennavigator()
hs.application.launchOrFocus("Anaconda-Navigator")
end
hotkey.bind(easykey, 'N', opennavigator)
hotkey.bind(easykey, 'Z', openzoom)
hotkey.bind(easykey, 'C', opencalendar)
hotkey.bind(easykey, 'G', openbrowser)
hotkey.bind(easykey, 'R', openrdp)
hotkey.bind(easykey, 'I', openemail)
-- hotkey.bind(easykey, 'Q', openqtcreator)
hotkey.bind(easykey, 'V', openvim) --macvim
hotkey.bind(easykey, 'D', openterminal)
hotkey.bind(easykey, 'E', openatom)
hotkey.bind(easykey, 'U', opengimp)
hotkey.bind(easykey, 'H', opentortoise)
hotkey.bind(easykey, 'M', openmusicplayer)
hotkey.bind(easykey, 'J', openchatprogram)
hotkey.bind(easykey, 'P', openpgadmin)
hotkey.bind(easykey, 'O', openmail)
-- hotkey.bind(easykey, 'N', openfinder)
hotkey.bind(easykey, 'L', openlaunchpad)
hotkey.bind(easykey, 'K', openkitematic)
--------------------------------------------------------------------------------
-- USEFUL TIDBITS IVE LEARNED ABOUT LUA / HS
--------------------------------------------------------------------------------
-- for _, i in ipairs(hs.application.runningApplications()) do print(i) end
-- This is an experiment to see how using hammerspoon://ramentime in alfred word, it works!
-- make sure MAKE SURE to type hammerspoon:// LOWER CASE
-- I really like that I am also able to use open hammerspoon://ramentime to access this function
-- RAMEN TIMER THROUGH ALFRED --
function startRamenTimer()
hs.timer.doAfter(3, function()
hs.notify.new({
title="Ramen time!",
informatieText="Your ramen is ready!"
}):send()
end)
hs.alert("Ramen timer started!")
end
function randomReviewer()
local reviewers = { 'John', 'Kevin', 'Chris', 'Ryan', 'Kendall', 'Jonathan' }
hs.alert(reviewers[math.random(#reviewers)])
end
hs.urlevent.bind("ramentime",startRamenTimer)
hs.urlevent.bind("who", randomReviewer)
----------------------- Addition window movements
hotkey.bind(hyper, "J", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y + (max.h / 2)
f.w = max.w
f.h = max.h / 2
win:setFrame(f)
end)
hotkey.bind(hyper, "K", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h / 2 + 9
win:setFrame(f)
end)
hotkey.bind(hyper, "H", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
hotkey.bind(hyper, "L", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
hs.alert(yay)
--------------------------------------------------------------------------------
-- Open these config settings
--------------------------------------------------------------------------------
hotkey.bind(hyper, "v", function()
hs.execute("code ~/src/dotfiles", true)
end
)