-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
162 lines (130 loc) · 4.13 KB
/
Copy pathinit.lua
File metadata and controls
162 lines (130 loc) · 4.13 KB
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
-- First execute the init.sh to download all the spoons
hs.alert.show("hammerspoon is initialized")
local hyper = {'ctrl', 'alt', 'cmd'}
local hyperShift = {'ctrl', 'alt', 'cmd', 'shift'}
-- Install spoons
hs.loadSpoon("SpoonInstall")
spoon.use_syncinstall = true
spoon.SpoonInstall:andUse("ReloadConfiguration")
spoon.SpoonInstall:andUse("Emojis")
spoon.SpoonInstall:andUse("TextClipboardHistory")
-- spoon.SpoonInstall:andUse("UnsplashRandom")
-- Reload configuration using a Spoon
spoon.ReloadConfiguration:start()
-- emojis shows
--spoon.Emojis:bindHotkeys({toggle = {hyper, 'f1'}})
-- show clipboard history
hs.hotkey.bind(hyper, "v", function() spoon.TextClipboardHistory:toggleClipboard() end)
spoon.TextClipboardHistory:start()
-- Window management
-- remove animations
hs.window.animationDuration = 0
-- set the default grid for all screens
hs.grid.setGrid'3x3'
hs.hotkey.bind(hyper, "right", function() moveWindow(1) end)
hs.hotkey.bind(hyper, "left", function() moveWindow(-1) end)
hs.hotkey.bind(hyper, "up", function() hs.grid.maximizeWindow() end)
hs.hotkey.bind(hyper, "down", function() fillVertical() end)
hs.hotkey.bind(hyperShift, "right", function() moveWindowToScreen(1) end)
hs.hotkey.bind(hyperShift, "left", function() moveWindowToScreen(-1) end)
-- Move the current focused window on the grid
-- expand the window if the windows is smaller than the halt
-- move the window if the window is bigger than half the grid
function moveWindow(direction)
local w = hs.window.frontmostWindow()
local s = w:screen()
local grid = hs.grid.getGrid(s)
local gridCell = hs.grid.get(w)
local halfWidth = math.ceil(grid.w / 2.0)
local left = direction < 0
local right = direction > 0
-- Try to move if width is already 3 of 5
if gridCell.w >= halfWidth then
-- if there is space to the right, and we want to move to the right
if right and gridCell.x2 < grid.w then
hs.grid.pushWindowRight(w)
return
end
-- if there is space to the right and we want to move to the left
if left and gridCell.x > 0 then
hs.grid.pushWindowLeft(w)
return
end
end
if right then
if gridCell.x2 > halfWidth then
hs.grid.resizeWindowThinner(w)
hs.grid.pushWindowRight(w)
else
hs.grid.resizeWindowWider(w)
end
end
if left then
if gridCell.x < halfWidth then
hs.grid.resizeWindowThinner(w)
hs.grid.pushWindowLeft(w)
else
hs.grid.resizeWindowWider(w)
end
end
end
function fillVertical()
local w = hs.window.frontmostWindow()
local s = w:screen()
local grid = hs.grid.getGrid(s)
local gridCell = hs.grid.get(w)
gridCell.y = 0
gridCell.h = grid.h
hs.grid.set(w, gridCell)
end
-- Move the current window to another screen
function moveWindowToScreen(direction)
local w = hs.window.frontmostWindow()
local s = w:screen()
local nextScreen
if direction > 0 then
nextScreen = s:toEast()
else
nextScreen = s:toWest()
end
w:moveToScreen(nextScreen)
end
-- Applications
local apps = {
-- c = 'Google Chrome',
c = 'Arc',
f = 'Finder',
t = 'wezterm',
p = 'KeePassXC',
s = 'Slack',
z = 'Zoom.us',
-- x = 'Tuple',
n = 'Obsidian',
d = 'Google Chat',
i = 'phpStorm',
v = 'Visual Studio Code',
}
for key, app in pairs(apps) do
hs.hotkey.bind(hyper, key, function() print(hs.application.launchOrFocus(app)) end)
end
-- copied from https://liuhao.im/english/2017/06/02/macos-automation-and-shortcuts-with-hammerspoon.html
function chrome_switch_to(ppl)
return function()
hs.application.launchOrFocus("Arc")
local chrome = hs.appfinder.appFromName("Arc")
local str_menu_item
if ppl == "Incognito" then
str_menu_item = {"File", "New Incognito Window"}
else
str_menu_item = {"Spaces", ppl}
end
local menu_item = chrome:findMenuItem(str_menu_item)
if (menu_item) then
chrome:selectMenuItem(str_menu_item)
end
end
end
--- open different Chrome users
hs.hotkey.bind(hyper, "1", chrome_switch_to("ThoughtWorks"))
hs.hotkey.bind(hyper, "2", chrome_switch_to("Civitatis"))
hs.hotkey.bind(hyper, "0", chrome_switch_to("Jordi"))