Skip to content

Instantly share code, notes, and snippets.

@jeebak
Last active December 28, 2017 20:09
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 jeebak/799b7a16a44385597c65af46666b5fd6 to your computer and use it in GitHub Desktop.
Save jeebak/799b7a16a44385597c65af46666b5fd6 to your computer and use it in GitHub Desktop.
Personalized keybindings for jasonrudolph/keyboard/hammerspoon WindowLayout Mode Raw
-- Personalized keybindings for jasonrudolph/keyboard/hammerspoon WindowLayout Mode
--
-- To customize the key bindings for WindowLayout Mode, create a copy of this
-- file, save it as `windows-bindings.lua`, and edit the table below to
-- configure your preferred shortcuts.
--------------------------------------------------------------------------------
-- Define WindowLayout Mode
--
-- In addition to the default keybindings:
--
-- https://github.com/jasonrudolph/keyboard/blob/master/hammerspoon/windows-bindings-defaults.lua
--
-- add, personalized functions and mappings:
--------------------------------------------------------------------------------
-- NOTE: Most of my Hammerspoon keybindings use "hyper" (⇧⌃⌥⌘) as the
-- modifiers. Karabiner-Elements is used to configure my Tab key to act as
-- hyper when held, and to emit a tab when tapped
-- https://pqrs.org/osx/karabiner/complex_modifications/#personal_jeebak
--------------------------------------------------------------------------------
windowLayoutMode:bindWithAutomaticExit({}, 'escape', function()
windowLayoutMode:exit()
end)
function hs.window.col3UpLeft(win) -- +-----------------+
hs.window.col3( -- |HERE | | |
win, 'Up', 'Left' -- +-----------------+
) -- | | | |
end -- +-----------------+
function hs.window.col3UpCenter(win) -- +-----------------+
hs.window.col3( -- | |HERE | |
win, 'Up', 'Center' -- +-----------------+
) -- | | | |
end -- +-----------------+
function hs.window.col3UpRight(win) -- +-----------------+
hs.window.col3( -- | | |HERE |
win, 'Up', 'Right' -- +-----------------+
) -- | | | |
end -- +-----------------+
function hs.window.col3FullLeft(win) -- +-----------------+
hs.window.col3( -- | H | | |
win, 'Full', 'Left' -- | ER | | |
) -- | E | | |
end -- +-----------------+
function hs.window.col3FullCenter(win) -- +-----------------+
hs.window.col3( -- | | H | |
win, 'Full', 'Center' -- | | ER | |
) -- | | E | |
end -- +-----------------+
function hs.window.col3FullRight(win) -- +-----------------+
hs.window.col3( -- | | | H |
win, 'Full', 'Right' -- | | | ER |
) -- | | | E |
end -- +-----------------+
function hs.window.col3DownLeft(win) -- +-----------------+
hs.window.col3( -- | | | |
win, 'Down', 'Left' -- +-----------------+
) -- |HERE | | |
end -- +-----------------+
function hs.window.col3DownCenter(win) -- +-----------------+
hs.window.col3( -- | | | |
win, 'Down', 'Center' -- +-----------------+
) -- | |HERE | |
end -- +-----------------+
function hs.window.col3DownRight(win) -- +-----------------+
hs.window.col3( -- | | | |
win, 'Down', 'Right' -- +-----------------+
) -- | | |HERE |
end -- +-----------------+
function hs.window.col3(win, vert, horz)
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
if horz == 'Left' then
f.x = max.x
elseif horz == 'Center' then
f.x = max.w / 3
elseif horz == 'Right' then
f.x = max.w * 2 / 3
end
f.y = max.y
f.w = max.w / 3
if vert == 'Up' then
f.h = max.h / 2
elseif vert == 'Full' then
f.h = max.h
elseif vert == 'Down' then
f.y = max.y + (max.h / 2)
f.h = max.h / 2
end
win:setFrame(f)
end
local hyper = {'ctrl', 'alt', 'cmd', 'shift'}
local hypo = {'ctrl', 'alt', 'cmd'}
return {
modifiers = hyper,
showHelp = true,
trigger = 'w',
mappings = {
{ hyper, '[', 'left40' },
{ hyper, ']', 'right60' },
{ {}, 'space', 'centerWithFullHeight' },
{ {}, 'j', 'left' },
{ {}, 'k', 'down' },
{ {}, 'i', 'up' },
{ {}, 'l', 'right' },
{ {}, 'u', 'upLeft' },
{ {}, 'o', 'upRight' },
{ {}, 'm', 'downLeft' },
{ {}, '.', 'downRight' },
{ {}, '/', 'nextScreen' },
{ {}, 'right', 'moveOneScreenEast' },
{ {}, 'left', 'moveOneScreenWest' },
{ hyper, ';', 'maximize' },
{ hyper, 'y', 'col3FullLeft' },
{ hyper, 'h', 'col3FullCenter' },
{ hyper, 'n', 'col3FullRight' },
{ hyper, 'u', 'col3UpLeft' },
{ hyper, 'i', 'col3UpCenter' },
{ hyper, 'o', 'col3UpRight' },
{ hyper, 'j', 'col3FullLeft' },
{ hyper, 'k', 'col3FullCenter' },
{ hyper, 'l', 'col3FullRight' },
{ hyper, 'm', 'col3DownLeft' },
{ hypo, ',', 'col3DownCenter' },
{ hypo, '.', 'col3DownRight' },
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment