-
Notifications
You must be signed in to change notification settings - Fork 12
/
init.lua
138 lines (108 loc) · 4.98 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
--------------------------------------------------------------------------------
-- Setup
--------------------------------------------------------------------------------
hyper = {'cmd', 'alt', 'ctrl'} -- or D+F 🤘
bigHyper = {'shift', 'cmd', 'alt', 'ctrl'} -- or S+D+F 😅
hs.loadSpoon('ReloadConfiguration'):start()
require('helpers')
require('area51')
positions = require('positions')
apps = require('apps')
layouts = require('layouts')
summon = require('summon')
chain = require('chain')
--------------------------------------------------------------------------------
-- Summon Specific Apps
--------------------------------------------------------------------------------
-- F13 to open summon modal
-- See `apps.lua` for `summon` modal bindings
local summonModalBindings = tableFlip(hs.fnutils.map(apps, function(app)
return app.summon
end))
registerModalBindings(nil, 'f13', hs.fnutils.map(summonModalBindings, function(app)
return function() summon(app) end
end), true)
--------------------------------------------------------------------------------
-- Misc Macros
--------------------------------------------------------------------------------
-- F14 to open macros modal
local macros = {
s = function() hs.eventtap.keyStroke({'cmd', 'shift'}, '4') end, -- screenshot
e = function() hs.eventtap.keyStroke({'cmd', 'ctrl'}, 'space') end, -- emoji picker
a = function() hs.eventtap.keyStroke({'cmd'}, '`') end, -- next window of focused app
c = function() hs.eventtap.keyStroke({'cmd', 'ctrl'}, 'c') end, -- color picker app
x = function() hs.eventtap.keyStroke({'cmd', 'ctrl'}, 'x') end, -- color picker eye dropper
}
registerModalBindings(nil, 'f14', macros, true)
--------------------------------------------------------------------------------
-- Multi Window Management
--------------------------------------------------------------------------------
-- hjkl focus window west/south/north/east
-- a unide [a]ll application windows
-- p [p]ick layout
-- m [m]aximize window
-- n [n]ext window in current cell, like `n/p` in vim
-- u warp [u]nder another window cell
-- ; toggle alternate layout
hs.window.animationDuration = 0
local layout = hs.loadSpoon('GridLayout')
:start()
:setLayouts(layouts)
:setApps(apps)
:setGrid('60x20')
:setMargins('15x15')
-- :setMargins('12x12') -- If I switch to Ghostty
if (hs.screen.primaryScreen():name() == 'LG HDR WQHD') then
layout:setMargins('30x30')
end
local windowManagementBindings = {
['h'] = function() hs.window.focusedWindow():focusWindowWest(nil, true) end,
['j'] = function() hs.window.focusedWindow():focusWindowSouth(nil, true) end,
['k'] = function() hs.window.focusedWindow():focusWindowNorth(nil, true) end,
['l'] = function() hs.window.focusedWindow():focusWindowEast(nil, true) end,
['a'] = function() hs.application.frontmostApplication():unhide() end,
['p'] = layout.selectLayout,
['u'] = layout.bindToCell,
[';'] = layout.selectNextVariant,
["'"] = layout.resetLayout,
-- ['m'] = toggleMaximized, -- Re-implement in GridLayout?
-- ['n'] = focusNextCellWindow, -- Re-implement in GridLayout?
}
registerKeyBindings(hyper, hs.fnutils.map(windowManagementBindings, function(fn)
return function() fn() end
end))
--------------------------------------------------------------------------------
-- Screencasting Customizations for 1280x720 HiDPI
--------------------------------------------------------------------------------
if (hs.screen.primaryScreen():name() == '24GL600F') then
layout:setMargins('12x12')
end
--------------------------------------------------------------------------------
-- Single Window Movements
--------------------------------------------------------------------------------
-- hl side column movements
-- k fullscreen and middle column movements
-- j centered window movements
-- yu top corner movements
-- nm bottom corner movements
-- i insert/snap to nearest grid region
local chainX = { 'thirds', 'halves', 'twoThirds', 'fiveSixths', 'sixths' }
local chainY = { 'full', 'thirds' }
local singleWindowMovements = {
['h'] = chain(getPositions(chainX, 'left')),
['k'] = chain(getPositions(chainY, 'center')),
['j'] = chain({ positions.center.large, positions.center.medium, positions.center.small, positions.center.tiny, positions.center.mini }),
['l'] = chain(getPositions(chainX, 'right')),
['y'] = chain(getPositions(chainX, 'left', 'top')),
['u'] = chain(getPositions(chainX, 'right', 'top')),
['n'] = chain(getPositions(chainX, 'left', 'bottom')),
['m'] = chain(getPositions(chainX, 'right', 'bottom')),
-- ['i'] = function() hs.grid.snap(hs.window.focusedWindow()) end, -- seems buggy?
}
registerKeyBindings(bigHyper, hs.fnutils.map(singleWindowMovements, function(fn)
return function() fn() end
end))
--------------------------------------------------------------------------------
-- The End
--------------------------------------------------------------------------------
hs.notify.show('Hammerspoon loaded', '', '...more like hammerspork')