Created
December 22, 2017 22:12
-
-
Save zyocum/ae5ea792fe5bb95021c94453517246c5 to your computer and use it in GitHub Desktop.
Hammerspoon config
This file contains 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
----------------------------------------------- | |
-- Set up | |
----------------------------------------------- | |
local hyper = {"cmd", "alt", "ctrl"} | |
hs.window.animationDuration = 0.05 | |
----------------------------------------------- | |
-- hyper left for left one half window | |
----------------------------------------------- | |
hs.hotkey.bind(hyper, 'left', function() | |
if hs.window.focusedWindow() then | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x - 4 | |
f.y = max.y | |
f.w = max.w / 2 | |
f.h = max.h | |
win:setFrame(f) | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
----------------------------------------------- | |
-- hyper right for right one half window | |
----------------------------------------------- | |
hs.hotkey.bind(hyper, 'right', function() | |
if hs.window.focusedWindow() then | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + (max.w / 2) - 4 | |
f.y = max.y | |
f.w = max.w / 2 + 4 | |
f.h = max.h | |
win:setFrame(f) | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
----------------------------------------------- | |
-- hyper return for fullscreen | |
----------------------------------------------- | |
hs.hotkey.bind(hyper, 'return', function() | |
if hs.window.focusedWindow() then | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x - 4 | |
f.y = max.y | |
f.w = max.w + 4 | |
f.h = max.h | |
win:setFrame(f) | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
----------------------------------------------- | |
-- hyper up for top half window | |
----------------------------------------------- | |
hs.hotkey.bind(hyper, 'up', function() | |
if hs.window.focusedWindow() then | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x - 4 | |
f.y = max.y | |
f.w = max.w + 4 | |
f.h = max.h / 2 | |
win:setFrame(f) | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
----------------------------------------------- | |
-- hyper down for bottom half window | |
----------------------------------------------- | |
hs.hotkey.bind(hyper, 'down', function() | |
if hs.window.focusedWindow() then | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x - 4 | |
f.y = max.h / 2 | |
f.w = max.w + 4 | |
f.h = max.h / 2 | |
win:setFrame(f) | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
----------------------------------------------- | |
-- hyper c for center two-thirds window | |
----------------------------------------------- | |
hs.hotkey.bind(hyper, 'c', function() | |
if hs.window.focusedWindow() then | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + (max.w / 6) - 4 | |
f.y = max.y | |
f.w = max.w * (2 / 3) + 4 | |
f.h = max.h | |
win:setFrame(f) | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
----------------------------------------------- | |
-- Reload config on write | |
----------------------------------------------- | |
function reload_config(files) | |
hs.reload() | |
end | |
hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reload_config):start() | |
hs.alert.show("Config loaded") | |
----------------------------------------------- | |
-- Hyper i to show window hints | |
----------------------------------------------- | |
hs.hotkey.bind(hyper, 'i', function() | |
hs.hints.windowHints() | |
end) | |
----------------------------------------------- | |
-- Hyper hjkl to switch window focus | |
----------------------------------------------- | |
hs.hotkey.bind(hyper, 'k', function() | |
if hs.window.focusedWindow() then | |
hs.window.focusedWindow():focusWindowNorth() | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
hs.hotkey.bind(hyper, 'j', function() | |
if hs.window.focusedWindow() then | |
hs.window.focusedWindow():focusWindowSouth() | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
hs.hotkey.bind(hyper, 'l', function() | |
if hs.window.focusedWindow() then | |
hs.window.focusedWindow():focusWindowEast() | |
else | |
hs.alert.show("No active window") | |
end | |
end) | |
hs.hotkey.bind(hyper, 'h', function() | |
if hs.window.focusedWindow() then | |
hs.window.focusedWindow():focusWindowWest() | |
else | |
hs.alert.show("No active window") | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment