Created
February 14, 2018 10:03
-
-
Save chrisnordqvist/d17806a0203657a249b8910010440449 to your computer and use it in GitHub Desktop.
My hammerspoon config
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
logger = hs.logger.new('main') | |
--- functions | |
function open(name) | |
return function() | |
hs.application.launchOrFocus(name) | |
if name == 'Finder' then | |
hs.appfinder.appFromName(name):activate() | |
end | |
end | |
end | |
--- quick open applications | |
hs.hotkey.bind({"alt"}, "E", open("Finder")) | |
hs.hotkey.bind({"alt"}, "C", open("Google Chrome")) | |
hs.hotkey.bind({"alt"}, "F", open("Fork")) | |
hs.hotkey.bind({"alt"}, "T", open("iTerm")) | |
hs.hotkey.bind({"alt"}, "X", open("Xcode")) | |
hs.hotkey.bind({"alt"}, "S", open("Sublime Text")) | |
hs.hotkey.bind({"alt"}, "A", open("Slack")) | |
hs.hotkey.bind({"alt"}, "M", open("Spotify")) | |
hs.hotkey.bind({"alt"}, "I", open("iTunes")) | |
hs.hotkey.bind({"alt"}, "Z", open("Zeplin")) | |
-- Resize window for chunk of screen. | |
-- For x and y: use 0 to expand fully in that dimension, 0.5 to expand halfway | |
-- For w and h: use 1 for full, 0.5 for half | |
function push(x, y, w, h) | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + (max.w*x) | |
f.y = max.y + (max.h*y) | |
f.w = max.w*w | |
f.h = max.h*h | |
win:setFrame(f) | |
end | |
--- window | |
hs.window.animationDuration = 0.125 | |
--- Detect if we're on a large or small screen | |
local screen = hs.screen.primaryScreen() | |
--- if we're on a smaller screen, use screen halves | |
--- on 34" Ultrawides go for 1/3s | |
if screen:frame().w < 2561 then | |
size = 1 / 2 | |
offset = size | |
else | |
size = 1 / 3 | |
offset = size * 2 | |
end | |
--- Bindings for smaller keyboards | |
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "Left", function() push(0, 0, size, 1) end) | |
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "Up", function() push(size, 0, size, 1) end) | |
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "Right", function() push(offset, 0, size, 1) end) | |
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "Down", function() push(0, 0, 1, 1) end) | |
--- Bindings for the full size magic keyboard | |
hs.hotkey.bind({}, "F13", function() push(0, 0, 0.5, 1) end) | |
hs.hotkey.bind({}, "F14", function() push(0, 0, 1, 1) end) | |
hs.hotkey.bind({}, "F15", function() push(0.5, 0, 0.5, 1) end) | |
hs.hotkey.bind({}, "F16", function() push(0, 0, 0.5, 0.5) end) | |
hs.hotkey.bind({}, "F17", function() push(0.5, 0, 0.5, 0.5) end) | |
hs.hotkey.bind({}, "F18", function() push(0, 0.5, 0.5, 0.5) end) | |
hs.hotkey.bind({}, "F19", function() push(0.5, 0.5, 0.5, 0.5) end) | |
--- Allow hot reloading of config | |
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function() | |
hs.reload() | |
end) | |
hs.alert.show("Config loaded") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment