Skip to content

Instantly share code, notes, and snippets.

@mrooney
Last active June 27, 2021 20:06
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 mrooney/c13e82b5811b2a87b5a413b7cb5f61ef to your computer and use it in GitHub Desktop.
Save mrooney/c13e82b5811b2a87b5a413b7cb5f61ef to your computer and use it in GitHub Desktop.
Hammerspoon basic configuration
---------------------
-- Config for https://www.hammerspoon.org/
-- Based on https://gist.github.com/philc/ed70ae4e60062c2d494fae97d5da43ce
-- see above for more advanced config including multiple display support
---------------------
-- the set of modifier keys you want to use with your shortcuts
local modifiers = {"cmd", "shift"}
-- make animations fast
hs.window.animationDuration = 0.1
---------------------
-- Window positioning
---------------------
function moveTopHalf()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h / 2
win:setFrame(f)
end
function moveBottomHalf()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y + (max.h / 2)
f.w = max.w
f.h = max.h / 2
win:setFrame(f)
end
function moveLeftHalf()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end
function moveRightHalf()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end
function maximize()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end
hs.hotkey.bind(modifiers, "left", function() moveLeftHalf() end)
hs.hotkey.bind(modifiers, "right", function() moveRightHalf() end)
hs.hotkey.bind(modifiers, "up", function() moveTopHalf() end)
hs.hotkey.bind(modifiers, "down", function() moveBottomHalf() end)
hs.hotkey.bind(modifiers, "m", maximize)
-- maximize is so common, also enable with just Cmd key, since I don't use the default OS X minimize shortcut
hs.hotkey.bind({"cmd"}, "m", maximize)
-------------------------------------
-- Application focusing shortcuts
-- When in doubt of the correct name, use the hover-text from the Dock icon.
-- QAZ are used due to being very easy to hit with the modifier keys on a QWERTY keyboard. Adjust as desired.
-------------------------------------
hs.hotkey.bind(modifiers, 'Q', function() hs.application.launchOrFocus('Google Chrome') end)
hs.hotkey.bind(modifiers, 'A', function() hs.application.launchOrFocus('Terminal') end)
hs.hotkey.bind(modifiers, 'Z', function() hs.application.launchOrFocus('Visual Studio Code') end)
hs.hotkey.bind(modifiers, 'S', function() hs.application.launchOrFocus('Slack') end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment