-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
167 lines (131 loc) · 5.82 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
-- main init.lua
-- By: Kellan St.Louis
-- Contact: [email protected]
-- hotky mash command for various things
local supermash = {"cmd", "alt", "ctrl"}
local minimash = {"ctrl", "alt"}
local shiftmash = {"ctrl", "alt", "shift"}
-- Quick and dirty command to toggle the Console window for Hammerspoon
hs.hotkey.bindSpec({supermash, "h" }, hs.toggleConsole)
-- loads the eGPU ejector spoon, which is STILL VERY MUCH NOT DONE
-- OWC has pushed an ejector tool for its docks. this kind of makes this spoon obsolete.
-- keeping it in case this turns out to work more reliably than the OWC tool, but that's unlikely.
-- hs.loadSpoon("eGPU")
-- spoon.eGPU:start()
-- loads the ControlEscape spoon, which is courtesy of Jason Rudolph
-- https://github.com/jasonrudolph/ControlEscape.spoon
-- I should really consider making this work for the Function key instead of Ctrl, easier to reach with short keyboard
hs.loadSpoon("ControlEscape")
spoon.ControlEscape:start()
-- removes animations, makes window movements happen supa fast
hs.window.animationDuration = 0
-- iTunes controls; change songs easily even when running in background
hs.hotkey.bind(supermash, 'right', hs.itunes.next)
hs.hotkey.bind(supermash, 'left', hs.itunes.previous)
hs.hotkey.bind(supermash, 'space', hs.itunes.playpause)
-- -- spoon for doing a quick toggle of DarkMode
-- -- this doesn't work, and I don't have the time to figure out why, so it's disabled for now.
-- -- it won't run with the key combo, but executes immediately when loaded.
-- hs.loadSpoon("ToggleDarkMode")
-- hs.hotkey.bind(supermash, 'l', spoon.ToggleDarkMode:switch())
-- "Shrug"
function kirby()
test = hs.alert.show(" ¯\\_(ツ)_/¯ ", 1.5)
hs.pasteboard.setContents("¯\\_(ツ)_/¯")
end
hs.hotkey.bind(supermash, 'K', kirby)
-- Mutes volume when not on home WiFi network
-- hopefully can also disable PIA vpn
wifiWatcher = nil
homeSSID = "weefee"
lastSSID = hs.wifi.currentNetwork()
function ssidChangedCallback()
newSSID = hs.wifi.currentNetwork()
if newSSID == homeSSID and lastSSID ~= homeSSID then
-- We just joined our home WiFi network
hs.audiodevice.defaultOutputDevice():setMuted(false)
os.execute("sudo pmset -a displaysleep 20 sleep 30")
hs.notify.new({title="Hammerspoon", informativeText="Mute Disabled"}):send()
hs.execute("piactl disconnect", true)
elseif newSSID ~= homeSSID and lastSSID == homeSSID then
-- We just departed our home WiFi network
hs.audiodevice.defaultOutputDevice():setMuted(true)
os.execute("sudo pmset -a displaysleep 5 sleep 10")
hs.notify.new({title="Hammerspoon", informativeText="Volume Mute Enabled"}):send()
hs.execute("piactl connect", true)
end
lastSSID = newSSID
end
wifiWatcher = hs.wifi.watcher.new(ssidChangedCallback)
wifiWatcher:start()
-- Reload Hammerspoon config, automatically when init.lua is saved. Show system notification.
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
myWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
hs.notify.new({title="Hammerspoon", informativeText="Config Loaded"}):send()
-- Defeat paste blocking by emitting fake keyboard events
hs.hotkey.bind(minimash, "V", function() hs.eventtap.keyStrokes(hs.pasteboard.getContents()) end)
-- === sizeup ===
-- SizeUp emulation for hammerspoon
-- stolen from https://gist.github.com/josephholsten/1e17c7418d9d8ec0e783
-- removed the bits I didn't want to use.
-- known issue: moving window to new monitor does not adjust menu bar. Active menu bar for that window
-- is still the menu bar from the previous monitor, until the window is interacted with ie made fullscreen
--imrovement: maintain current fullscreen state when moving window that is already fullscreen
-- way to do this: maybe "if fullscreen, then set fullscreen to false, then move"
-- maybe too janky and long. remove animations or speed up somehow?
local sizeup = { }
--- Multiple Monitor Actions ---
-- Send Window Prev Monitor
hs.hotkey.bind(minimash, "Left", function()
sizeup.send_window_prev_monitor()
end)
--Send Window Prev Monitor, then make fullscreen --still beta? not super confident yet
hs.hotkey.bind(shiftmash, "Left", function()
sizeup.send_window_prev_monitor()
local win = hs.window.focusedWindow()
win:setFullScreen(not win:isFullScreen())
end)
-- Send Window Next Monitor
hs.hotkey.bind(minimash, "Right", function()
sizeup.send_window_next_monitor()
end)
--Send Window Next Monitor, then make fullscreen --still beta? not super confident yet
hs.hotkey.bind(shiftmash, "Right", function()
sizeup.send_window_next_monitor()
local win = hs.window.focusedWindow()
win:setFullScreen(not win:isFullScreen())
end)
function sizeup.send_window_prev_monitor()
hs.alert.show("Prev Monitor")
local win = hs.window.focusedWindow()
local nextScreen = win:screen():previous()
win:moveToScreen(nextScreen)
end
function sizeup.send_window_next_monitor()
hs.alert.show("Next Monitor")
local win = hs.window.focusedWindow()
local nextScreen = win:screen():next()
win:moveToScreen(nextScreen)
end
--- move window to the the given screen, keeping the relative proportion and position window to the original screen.
function hs.window:moveToScreen(nextScreen)
local currentFrame = self:frame()
local screenFrame = self:screen():frame()
local nextScreenFrame = nextScreen:frame()
self:setFrame({
x = ((((currentFrame.x - screenFrame.x) / screenFrame.w) * nextScreenFrame.w) + nextScreenFrame.x),
y = ((((currentFrame.y - screenFrame.y) / screenFrame.h) * nextScreenFrame.h) + nextScreenFrame.y),
h = ((currentFrame.h / screenFrame.h) * nextScreenFrame.h),
w = ((currentFrame.w / screenFrame.w) * nextScreenFrame.w)
})
end