Last active
August 14, 2026 13:42
-
-
Save jgpawletko/9527674 to your computer and use it in GitHub Desktop.
my Hammerspoon init.lua file
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
| -- ============================================================================= | |
| -- Hammerspoon Configuration (Translated from Slate) | |
| -- ============================================================================= | |
| -- Disable window animation delay for instant moves/resizes | |
| hs.window.animationDuration = 0 | |
| local hyper = {"ctrl", "alt"} | |
| local hyperShift = {"ctrl", "alt", "shift"} | |
| local resizeMods = {"ctrl", "cmd"} | |
| local resizeModsShift = {"ctrl", "cmd", "shift"} | |
| -- Helper function to set window frames using unit rectangles {x, y, w, h} | |
| local function moveWindow(x, y, w, h) | |
| local win = hs.window.focusedWindow() | |
| if win then | |
| win:moveToUnit({x, y, w, h}) | |
| end | |
| end | |
| -- Helper function to nudge window position by percentage | |
| local function nudgeWindow(dx, dy) | |
| local win = hs.window.focusedWindow() | |
| if not win then return end | |
| local frame = win:frame() | |
| local screenFrame = win:screen():frame() | |
| frame.x = frame.x + (screenFrame.w * dx) | |
| frame.y = frame.y + (screenFrame.h * dy) | |
| win:setFrame(frame) | |
| end | |
| -- Helper function to resize window frame by percentage | |
| local function resizeWindow(dw, dh) | |
| local win = hs.window.focusedWindow() | |
| if not win then return end | |
| local frame = win:frame() | |
| local screenFrame = win:screen():frame() | |
| frame.w = frame.w + (screenFrame.w * dw) | |
| frame.h = frame.h + (screenFrame.h * dh) | |
| win:setFrame(frame) | |
| end | |
| -- Helper function to throw window to specific screen index | |
| local function throwToScreen(screenIndex) | |
| local win = hs.window.focusedWindow() | |
| if not win then return end | |
| local screens = hs.screen.allScreens() | |
| if screens[screenIndex] then | |
| win:moveToScreen(screens[screenIndex], true, true) | |
| end | |
| end | |
| -- ============================================================================= | |
| -- 1. Screen Throws (pad0, pad.) | |
| -- ============================================================================= | |
| hs.hotkey.bind(hyper, "pad.", function() throwToScreen(1) end) | |
| hs.hotkey.bind(hyper, "pad0", function() throwToScreen(2) end) | |
| -- ============================================================================= | |
| -- 2. Numpad Layout Binds (Ctrl + Alt + Keypad) | |
| -- ============================================================================= | |
| hs.hotkey.bind(hyper, "pad1", function() moveWindow(0.0, 0.5, 0.5, 0.5) end) -- bottomleft | |
| hs.hotkey.bind(hyper, "pad2", function() moveWindow(0.0, 0.5, 1.0, 0.5) end) -- bottomhalf | |
| hs.hotkey.bind(hyper, "pad3", function() moveWindow(0.5, 0.5, 0.5, 0.5) end) -- bottomright | |
| hs.hotkey.bind(hyper, "pad4", function() moveWindow(0.0, 0.0, 0.5, 1.0) end) -- lefthalf | |
| hs.hotkey.bind(hyper, "pad5", function() moveWindow(0.0, 0.0, 1.0, 1.0) end) -- full | |
| hs.hotkey.bind(hyper, "pad6", function() moveWindow(0.5, 0.0, 0.5, 1.0) end) -- righthalf | |
| hs.hotkey.bind(hyper, "pad7", function() moveWindow(0.0, 0.0, 0.5, 0.5) end) -- topleft | |
| hs.hotkey.bind(hyper, "pad8", function() moveWindow(0.0, 0.0, 1.0, 0.5) end) -- tophalf | |
| hs.hotkey.bind(hyper, "pad9", function() moveWindow(0.5, 0.0, 0.5, 0.5) end) -- topright | |
| -- Quarters variant (Ctrl + Alt + Shift + Keypad) | |
| hs.hotkey.bind(hyperShift, "pad1", function() moveWindow(0.0, 0.75, 0.5, 0.25) end) -- bottomleftquarter | |
| hs.hotkey.bind(hyperShift, "pad2", function() moveWindow(0.0, 0.75, 1.0, 0.25) end) -- bottomquarter | |
| hs.hotkey.bind(hyperShift, "pad3", function() moveWindow(0.5, 0.75, 0.5, 0.25) end) -- bottomrightquarter | |
| hs.hotkey.bind(hyperShift, "pad7", function() moveWindow(0.0, 0.00, 0.5, 0.25) end) -- topleftquarter | |
| hs.hotkey.bind(hyperShift, "pad8", function() moveWindow(0.0, 0.00, 1.0, 0.25) end) -- topquarter | |
| hs.hotkey.bind(hyperShift, "pad9", function() moveWindow(0.5, 0.00, 0.5, 0.25) end) -- toprightquarter | |
| -- ============================================================================= | |
| -- 3. Nudges (Ctrl + Alt + Arrows) | |
| -- ============================================================================= | |
| hs.hotkey.bind(hyper, "left", function() nudgeWindow(-0.10, 0.00) end) | |
| hs.hotkey.bind(hyper, "right", function() nudgeWindow( 0.10, 0.00) end) | |
| hs.hotkey.bind(hyper, "up", function() nudgeWindow( 0.00,-0.10) end) | |
| hs.hotkey.bind(hyper, "down", function() nudgeWindow( 0.00, 0.10) end) | |
| hs.hotkey.bind(hyperShift, "left", function() nudgeWindow(-0.05, 0.00) end) | |
| hs.hotkey.bind(hyperShift, "right", function() nudgeWindow( 0.05, 0.00) end) | |
| hs.hotkey.bind(hyperShift, "up", function() nudgeWindow( 0.00,-0.05) end) | |
| hs.hotkey.bind(hyperShift, "down", function() nudgeWindow( 0.00, 0.05) end) | |
| -- ============================================================================= | |
| -- 4. Stretches / Resizes (Ctrl + Cmd + Arrows) | |
| -- ============================================================================= | |
| hs.hotkey.bind(resizeMods, "left", function() resizeWindow(-0.10, 0.00) end) | |
| hs.hotkey.bind(resizeMods, "right", function() resizeWindow( 0.10, 0.00) end) | |
| hs.hotkey.bind(resizeMods, "up", function() resizeWindow( 0.00,-0.10) end) | |
| hs.hotkey.bind(resizeMods, "down", function() resizeWindow( 0.00, 0.10) end) | |
| hs.hotkey.bind(resizeModsShift, "left", function() resizeWindow(-0.05, 0.00) end) | |
| hs.hotkey.bind(resizeModsShift, "right", function() resizeWindow( 0.05, 0.00) end) | |
| hs.hotkey.bind(resizeModsShift, "up", function() resizeWindow( 0.00,-0.05) end) | |
| hs.hotkey.bind(resizeModsShift, "down", function() resizeWindow( 0.00, 0.05) end) | |
| -- ============================================================================= | |
| -- 5. Focus Bindings (Cmd + Arrows & Cmd + Alt + Up/Down) | |
| -- ============================================================================= | |
| hs.hotkey.bind({"cmd"}, "right", function() hs.window.focusedWindow():focusWindowEast() end) | |
| hs.hotkey.bind({"cmd"}, "left", function() hs.window.focusedWindow():focusWindowWest() end) | |
| hs.hotkey.bind({"cmd"}, "up", function() hs.window.focusedWindow():focusWindowNorth() end) | |
| hs.hotkey.bind({"cmd"}, "down", function() hs.window.focusedWindow():focusWindowSouth() end) | |
| -- Focus behind (send focus to window directly underneath current window) | |
| hs.hotkey.bind({"cmd", "alt"}, "up", function() | |
| local win = hs.window.focusedWindow() | |
| if win then win:sendToBack() end | |
| end) | |
| hs.hotkey.bind({"cmd", "alt"}, "down", function() | |
| local win = hs.window.focusedWindow() | |
| if win then win:sendToBack() end | |
| end) | |
| -- ============================================================================= | |
| -- 6. Commented Out Binds (Window Hints & Grid - Optional) | |
| -- Un-comment lines below if you want window hinting (cmd+e) or grid (cmd+g) | |
| -- ============================================================================= | |
| -- hs.hotkey.bind({"cmd"}, "e", function() hs.hints.windowHints() end) | |
| -- hs.hotkey.bind({"cmd"}, "g", function() hs.grid.show() end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment