-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhammerspoon.lua
136 lines (121 loc) · 3.31 KB
/
hammerspoon.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
--- Lore's Hammerspoon config ---
---------------
--- GLOBALS ---
---------------
hs.window.animationDuration = 0
------------
--- KEYS ---
------------
local hyper = {"ctrl", "option", "cmd", "shift"}
local keys = {
["specials"] = {
["Reload"] = {hyper, "r"},
["Fullscreen window"] = {hyper, "y"},
["Center window"] = {hyper, "k"},
["Left 50% window"] = {hyper, "h"},
["Right 50% window"] = {hyper, "l"},
["Move window display left"] = {hyper, "["},
["Move window display right"] = {hyper, "]"},
["RustRover"] = {{"option"}, "c"},
},
["apps"] = {
["Alacritty"] = {{"option"}, "a"},
["Vivaldi"] = {{"option"}, "v"},
["Finder"] = {{"option"}, "f"},
},
}
----------------
--- SPECIALS ---
----------------
local specials = {
["Reload"] = hs.reload,
}
specials["Fullscreen window"] = function()
local win = hs.window.focusedWindow()
if not win then hs.alert.show("Can't move window"); return end
local screen = win:screen()
local max = screen:frame()
win:setFrame(max)
end
specials["Center window"] = function()
local win = hs.window.focusedWindow()
if not win then hs.alert.show("Can't move window"); return end
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
if max.x < 0 then
-- If on screen on the left of the main display
f.x = max.x + f.w / 2
else
f.x = (max.w - f.w) / 2
end
f.y = (max.h - f.h) / 2
win:setFrame(f)
end
specials["Left 50% window"] = function()
local win = hs.window.focusedWindow()
if not win then hs.alert.show("Can't move window"); return end
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
specials["Right 50% window"] = function()
local win = hs.window.focusedWindow()
if not win then hs.alert.show("Can't move window"); return end
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
if max.x < 0 then
-- If on screen on the left of the main display
f.x = max.x + max.w / 2
else
f.x = max.x2 / 2
end
f.y = max.y
f.x2 = max.x2
f.y2 = max.y2
win:setFrame(f)
end
specials["Move window display left"] = function()
local win = hs.window.focusedWindow()
if not win then hs.alert.show("Can't move window"); return end
win:moveOneScreenWest()
end
specials["Move window display right"] = function()
local win = hs.window.focusedWindow()
if not win then hs.alert.show("Can't move window"); return end
win:moveOneScreenEast()
end
-- because RustRover with remote gateway can lead to multiple applications, we
-- need to handle it differently than normal apps
specials["RustRover"] = function()
a, b = hs.application.find("RustRover")
if b ~= nil and not b:isFrontmost() then
b:activate()
elseif a ~= nil then
a:activate()
else
hs.application.launchOrFocus("RustRover 2023.3 EAP")
end
end
------------
--- INIT ---
------------
function registerHotkey(name, key, fn)
local hotkey = hs.hotkey.new(key[1], key[2], fn)
hotkey:enable()
end
for appName, key in pairs(keys.apps) do
registerHotkey(appName, key, function()
hs.application.launchOrFocus(appName)
end)
end
for specialName, key in pairs(keys.specials) do
registerHotkey(specialName, key, specials[specialName])
end
hs.alert.show("Hammerspoon loaded!")