Created
September 21, 2015 12:49
-
-
Save zachfedor/46d826b093d60460c41f to your computer and use it in GitHub Desktop.
Hammerspoon Config File
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
------------------------ | |
-- Hammerspoon Init -- | |
------------------------ | |
-- Global Variables | |
gutter = 20 | |
editor = "Atom" | |
-- Welcome Messages | |
hs.hotkey.bind({"cmd", "ctrl"}, "W", function() | |
hs.alert.show("hello world") | |
end) | |
hs.hotkey.bind({"cmd", "ctrl", "shift"}, "W", function() | |
hs.notify.new({title="Hammerspoon", informativeText="Hello World"}):send():release() | |
end) | |
--------------------- | |
-- Window Sizing -- | |
--------------------- | |
-- Maximized | |
hs.hotkey.bind({"ctrl"}, "M", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + gutter | |
f.y = max.y + gutter | |
f.w = max.w - (gutter * 2) | |
f.h = max.h - (gutter * 2) | |
win:setFrame(f) | |
end) | |
-- Left Half | |
hs.hotkey.bind({"ctrl"}, "H", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + gutter | |
f.y = max.y + gutter | |
f.w = (max.w / 2) - (gutter * 1.5) | |
f.h = max.h - (gutter * 2) | |
win:setFrame(f) | |
end) | |
-- Right Half | |
hs.hotkey.bind({"ctrl"}, "L", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + (max.w / 2) + (gutter / 2) | |
f.y = max.y + gutter | |
f.w = (max.w / 2) - (gutter * 1.5) | |
f.h = max.h - (gutter * 2) | |
win:setFrame(f) | |
end) | |
-- Top Half | |
hs.hotkey.bind({"ctrl"}, "K", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + gutter | |
f.y = max.y + gutter | |
f.w = max.w - (gutter * 2) | |
f.h = (max.h / 2) - (gutter * 1.5) | |
win:setFrame(f) | |
end) | |
-- Bottom Half | |
hs.hotkey.bind({"ctrl"}, "J", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + gutter | |
f.y = (max.h / 2) + (gutter * 2) | |
f.w = max.w - (gutter * 2) | |
f.h = (max.h / 2) - (gutter * 1.5) | |
win:setFrame(f) | |
end) | |
-- Top Left Quarter | |
hs.hotkey.bind({"ctrl"}, "Y", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + gutter | |
f.y = max.y + gutter | |
f.w = (max.w / 2) - (gutter * 1.5) | |
f.h = (max.h / 2) - (gutter * 1.5) | |
win:setFrame(f) | |
end) | |
-- Top Right Quarter | |
hs.hotkey.bind({"ctrl"}, "U", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = (max.w / 2) + (gutter / 2) | |
f.y = max.y + gutter | |
f.w = (max.w / 2) - (gutter * 1.5) | |
f.h = (max.h / 2) - (gutter * 1.5) | |
win:setFrame(f) | |
end) | |
-- Bottom Left Quarter | |
hs.hotkey.bind({"ctrl"}, "B", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + gutter | |
f.y = (max.h / 2) + (gutter * 2) | |
f.w = (max.w / 2) - (gutter * 1.5) | |
f.h = (max.h / 2) - (gutter * 1.5) | |
win:setFrame(f) | |
end) | |
-- Bottom Right Quarter | |
hs.hotkey.bind({"ctrl"}, "N", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = (max.w / 2) + (gutter / 2) | |
f.y = (max.h / 2) + (gutter * 2) | |
f.w = (max.w / 2) - (gutter * 1.5) | |
f.h = (max.h / 2) - (gutter * 1.5) | |
win:setFrame(f) | |
end) | |
-- Window Movement | |
hs.hotkey.bind({"cmd", "ctrl"}, "Y", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.x = f.x - gutter | |
f.y = f.y - gutter | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "K", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.y = f.y - gutter | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "U", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.x = f.x + gutter | |
f.y = f.y - gutter | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "H", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.x = f.x - gutter | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "L", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.x = f.x + gutter | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "B", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.x = f.x - gutter | |
f.y = f.y + gutter | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "J", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.y = f.y + gutter | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "N", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.x = f.x + gutter | |
f.y = f.y + gutter | |
win:setFrame(f) | |
end) | |
-- 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 Reloaded") | |
-------------------------------- | |
-- Here be some nonsense... -- | |
-------------------------------- | |
-- Find The Cursor | |
local mouseCircle = nil | |
local mouseCircleTimer = nil | |
function mouseHighlight() | |
-- Delete an existing highlight if it exists | |
if mouseCircle then | |
mouseCircle:delete() | |
if mouseCircleTimer then | |
mouseCircleTimer:stop() | |
end | |
end | |
-- Get the current co-ordinates of the mouse pointer | |
mousepoint = hs.mouse.get() | |
-- Prepare a big red circle around the mouse pointer | |
mouseCircle = hs.drawing.circle(hs.geometry.rect(mousepoint.x-50, mousepoint.y-50, 100, 100)) | |
mouseCircle:setStrokeColor({["red"]=0.85,["blue"]=0.2,["green"]=0.1,["alpha"]=0.9}) | |
mouseCircle:setFill(false) | |
mouseCircle:setStrokeWidth(8) | |
mouseCircle:show() | |
-- Set a timer to delete the circle after 3 seconds | |
mouseCircleTimer = hs.timer.doAfter(3, function() mouseCircle:delete() end) | |
end | |
hs.hotkey.bind({"cmd","alt","shift"}, "D", mouseHighlight) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment