Created
July 25, 2020 11:47
-
-
Save aladhims/3d847db8c5d91983cb6bae50e4249567 to your computer and use it in GitHub Desktop.
My Personal Hammerspoon Configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local hyper = { "cmd", "alt", "ctrl", "shift" } | |
hs.hotkey.bind(hyper, "0", function() | |
hs.reload() | |
end) | |
hs.notify.new({title="Hammerspoon", informativeText="Config loaded"}):send() | |
hs.hotkey.bind(hyper, "l", function() | |
hs.caffeinate.lockScreen() | |
end) | |
hs.hotkey.bind(hyper, "z", function() | |
hs.caffeinate.systemSleep() | |
end) | |
hs.hotkey.bind(hyper, "f", function() | |
local win = hs.window.frontmostWindow() | |
win:setFullscreen(not win:isFullscreen()) | |
end) | |
hs.hotkey.bind(hyper, "m", function() | |
local win = hs.window.focusedWindow() | |
win:minimize(not win:isMinimized()) | |
end) | |
hs.window.animationDuration = 0 | |
local applicationHotkeys = { | |
c = 'Google Chrome', | |
x = 'Calendar', | |
t = 'iTerm', | |
s = 'Slack', | |
e = 'Goland', | |
a = 'Music', | |
i = 'Spark', | |
r = 'Todoist', | |
w = 'Notion', | |
d = 'Stocks' | |
} | |
for key, app in pairs(applicationHotkeys) do | |
hs.hotkey.bind(hyper, key, function() | |
hs.application.launchOrFocus(app) | |
end) | |
end | |
function pingResult(object, message, seqnum, error) | |
if message == "didFinish" then | |
avg = tonumber(string.match(object:summary(), '/(%d+.%d+)/')) | |
if avg == 0.0 then | |
hs.alert.show("No network") | |
elseif avg < 200.0 then | |
hs.alert.show("Network good (" .. avg .. "ms)") | |
elseif avg < 500.0 then | |
hs.alert.show("Network poor(" .. avg .. "ms)") | |
else | |
hs.alert.show("Network bad(" .. avg .. "ms)") | |
end | |
end | |
end | |
hs.hotkey.bind(hyper, "p", function()hs.network.ping.ping("8.8.8.8", 1, 0.01, 1.0, "any", pingResult)end) | |
function move_window(direction) | |
return function() | |
local win = hs.window.focusedWindow() | |
local app = win:application() | |
local app_name = app:name() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
if direction == "left" then | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w / 2 | |
f.h = max.h | |
elseif direction == "right" then | |
f.x = max.x + (max.w / 2) | |
f.y = max.y | |
f.w = max.w / 2 | |
f.h = max.h | |
elseif direction == "up" then | |
f.x = max.x | |
f.w = max.w | |
f.y = max.y | |
f.h = max.h / 2 | |
elseif direction == "down" then | |
f.x = max.x | |
f.w = max.w | |
f.y = max.y + (max.h / 2) | |
f.h = max.h / 2 | |
elseif direction == "upLeft" then | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w/2 | |
f.h = max.h/2 | |
elseif direction == "upRight" then | |
f.x = max.x + (max.w / 2) | |
f.y = max.y | |
f.w = max.w/2 | |
f.h = max.h/2 | |
elseif direction == "downLeft" then | |
f.x = max.x | |
f.y = max.y + (max.h / 2) | |
f.w = max.w/2 | |
f.h = max.h/2 | |
elseif direction == "downRight" then | |
f.x = max.x + (max.w / 2) | |
f.y = max.y + (max.h / 2) | |
f.w = max.w/2 | |
f.h = max.h/2 | |
end | |
win:setFrame(f) | |
end | |
end | |
hs.hotkey.bind(hyper, "Left", move_window("left")) | |
hs.hotkey.bind(hyper, "Right", move_window("right")) | |
hs.hotkey.bind(hyper, "Up", move_window("up")) | |
hs.hotkey.bind(hyper, "Down", move_window("down")) | |
hs.hotkey.bind(hyper, "[", move_window("upLeft")) | |
hs.hotkey.bind(hyper, "\\", move_window("upRight")) | |
hs.hotkey.bind(hyper, "'", move_window("downLeft")) | |
hs.hotkey.bind(hyper, "home", move_window("downRight")) | |
hs.hotkey.bind(hyper, "return", function() | |
local win = hs.window.focusedWindow(); | |
if not win then return end | |
win:moveToUnit(hs.layout.maximized) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment