Skip to content

Instantly share code, notes, and snippets.

@theodesp
Created November 30, 2016 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theodesp/7d97d453f66688df1da768ef7db6709f to your computer and use it in GitHub Desktop.
Save theodesp/7d97d453f66688df1da768ef7db6709f to your computer and use it in GitHub Desktop.
My Hammerspoon configuration
-- Configuration reloader
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
local myWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
hs.alert.show("Config loaded")
--
-- Key definitions
--
local cah = {"cmd", "alt", "ctrl"}
local cahs = {"cmd", "alt", "ctrl", "shift"}
--
-- Window manipulation
--
-- Grid setup
hs.grid.MARGINX = 0
hs.grid.MARGINY = 0
hs.grid.GRIDWIDTH = 10
hs.grid.GRIDHEIGHT = 2
-- a helper function that returns another function that resizes the current window
-- to a certain grid size.
local gridset = function(x, y, w, h)
return function()
local win = hs.window.focusedWindow()
hs.grid.set(
win,
{x=x, y=y, w=w, h=h},
win:screen()
)
end
end
-- Maximize window
hs.hotkey.bind(cah, "M", function()
hs.grid.maximizeWindow(hs.window.focusedWindow())
end)
-- Left 1/2 of the screen
hs.hotkey.bind(cah, "Left", gridset(0, 0, 5, 2))
-- Right 1/2 of the screen
hs.hotkey.bind(cah, "Right", gridset(5, 0, 5, 2))
-- Top 1/2 of the screen
hs.hotkey.bind(cah, "Up", gridset(0, 0, 10, 0))
-- Bottom 1/2 of the screen
hs.hotkey.bind(cah, "Down", gridset(0, 5, 10, 5))
-- Left 7/10 of the screen
hs.hotkey.bind(cah, "1", gridset(0, 0, 7, 2))
-- Top right corner 3/10 of the screen
hs.hotkey.bind(cah, "2", gridset(7, 0, 3, 1))
-- Bottom right corner 3/10 of the screen
hs.hotkey.bind(cah, "3", gridset(7, 1, 3, 1))
-- Bottom right corner 4/10 of the screen
hs.hotkey.bind(cah, "4", gridset(6, 1, 4, 1))
-- Resize window on grid
hs.hotkey.bind(cahs, "H", function()
hs.grid.resizeWindowThinner(hs.window.focusedWindow())
end)
hs.hotkey.bind(cahs, "J", function()
hs.grid.resizeWindowShorter(hs.window.focusedWindow())
end)
hs.hotkey.bind(cahs, "K", function()
hs.grid.resizeWindowTaller(hs.window.focusedWindow())
end)
hs.hotkey.bind(cahs, "L", function()
hs.grid.resizeWindowWider(hs.window.focusedWindow())
end)
-- End Window manipulation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment