Skip to content

Instantly share code, notes, and snippets.

@pazimzadeh
Created November 30, 2023 17:16
Show Gist options
  • Save pazimzadeh/b1c70f5f205d0b63264e7c0213ef7afc to your computer and use it in GitHub Desktop.
Save pazimzadeh/b1c70f5f205d0b63264e7c0213ef7afc to your computer and use it in GitHub Desktop.
My Hammerspoon config file
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
hs.reload()
end)
hs.alert.show("Config loaded")
hs.loadSpoon("ShiftIt")
spoon.ShiftIt:bindHotkeys({})
spoon.ShiftIt:bindHotkeys({
left = {{ 'alt', 'cmd' }, 'z' },
right = {{ 'alt', 'cmd' }, 'x' },
up = {{ 'alt', 'cmd' }, 'q' },
down = {{ 'alt', 'cmd' }, 'a' },
resizeIn = {{ 'alt', 'cmd' }, '-' },
resizeOut = {{ 'alt', 'cmd' }, '=' },
toggleZoom = {{ 'alt', 'cmd' }, 'f' },
upleft = {{ 'alt', 'cmd' }, '1' },
upright = {{ 'alt', 'cmd' }, '2' },
botleft = {{ 'alt', 'cmd' }, '3' },
botright = {{ 'alt', 'cmd' }, '4' }
})
hs.hotkey.bind({"cmd", "alt"}, "s", function()
-- size focused window to middle third of display
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 3)
f.y = max.y
f.w = max.w / 3
f.h = max.h
win:setFrame(f)
end)
-- move window to next screen
-- bind hotkey
hs.hotkey.bind({'alt', 'ctrl', 'cmd'}, ']', function()
-- get the focused window
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the next screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
end)
-- move window to previous screen
-- bind hotkey
hs.hotkey.bind({'alt', 'ctrl', 'cmd'}, '[', function()
-- get the focused window
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the previous screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:previous(), true, 0)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment