Last active
January 13, 2016 02:12
-
-
Save colinrymer/bde6cff2c22d0df09811 to your computer and use it in GitHub Desktop.
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
----------------------------------------------- | |
-- Auto Config Reload | |
----------------------------------------------- | |
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 | |
hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start() | |
hs.alert.show("Config loaded") | |
----------------------------------------------- | |
-- Set up | |
----------------------------------------------- | |
local hyper = {"shift", "cmd", "alt", "ctrl"} | |
----------------------------------------------- | |
-- vim-like window movement | |
-- hyper m for fullscreen | |
----------------------------------------------- | |
for key, dir in pairs({ h = "left", j = "down", k = "up", l = "right", m = "max", c="center" }) do | |
hs.hotkey.bind(hyper, key, function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local max = win:screen():frame() | |
f.x = (dir == "right") and (max.x + (max.w / 2)) or (dir == "center" and max.x + (max.w / 4)) or max.x | |
f.y = (dir == "down") and (max.y + (max.h / 2)) or (dir == "center" and max.y + (max.h / 4)) or max.y | |
f.w = (dir == "left" or dir == "right" or dir == "center") and (max.w / 2) or max.w | |
f.h = (dir == "up" or dir == "down" or dir == "center") and (max.h / 2) or max.h | |
win:setFrame(f) | |
end) | |
end | |
----------------------------------------------- | |
-- application hotkeys | |
----------------------------------------------- | |
for key, name in pairs({ | |
c = "Google Chrome", | |
f = "Finder", | |
m = "Messages", | |
p = "Spotify", | |
s = "Slack", | |
t = "iTerm", | |
v = "Sococo" | |
}) do | |
hs.hotkey.bind({"cmd", "alt"}, key, function() | |
local app = hs.application.get(name) | |
if app and app:isFrontmost() then | |
app:hide() | |
else | |
hs.application.launchOrFocus(name) | |
end | |
end) | |
end | |
hs.hotkey.bind(hyper, "space", hs.spotify.displayCurrentTrack) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment