Created
January 23, 2017 21:26
-
-
Save evantravers/8159ab68aaef66113da27fd51ef1bf0f to your computer and use it in GitHub Desktop.
This file contains 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
-- A global variable for the sub-key Hyper Mode | |
k = hs.hotkey.modal.new({}, 'F18') | |
-- Hyper+key for all the below are setup somewhere | |
-- The handler already exists, usually in Keyboard Maestro | |
-- we just have to get the right keystroke sent | |
hyperBindings = {'c', 'space'} | |
for i,key in ipairs(hyperBindings) do | |
k:bind({}, key, nil, function() hs.eventtap.keyStroke({'cmd','alt','shift','ctrl'}, key) | |
k.triggered = true | |
end) | |
end | |
-- Enter Hyper Mode when F19 (left control) is pressed | |
pressedF19 = function() | |
k.triggered = false | |
k:enter() | |
end | |
-- Leave Hyper Mode when F19 (left control) is pressed, | |
-- send ESCAPE if no other keys are pressed. | |
releasedF19 = function() | |
k:exit() | |
if not k.triggered then | |
hs.eventtap.keyStroke({}, 'ESCAPE') | |
end | |
end | |
-- Bind the Hyper key | |
f19 = hs.hotkey.bind({}, 'F19', pressedF19, releasedF19) | |
launch = function(appname) | |
hs.application.launchOrFocus(appname) | |
k.triggered = true | |
end | |
-- Single keybinding for app launch | |
singleapps = { | |
{'j', 'iTerm'}, | |
{'k', 'Google Chrome'}, | |
{'h', 'Dash'}, | |
{'i', 'Slack'}, | |
{'e', 'Airmail 2'}, | |
{'m', 'Fantastical 2'}, | |
{'n', 'Hipchat'}, | |
{'f', 'Finder'} | |
} | |
for i, app in ipairs(singleapps) do | |
k:bind({}, app[1], function() launch(app[2]); k:exit(); end) | |
end | |
-- Window shortcuts from @tmiller | |
local screenMode = hs.hotkey.modal.new('cmd', 'm') | |
function screenMode:entered() | |
alertUuids = hs.fnutils.imap(hs.screen.allScreens(), function(screen) | |
return hs.alert.show('Move Window', hs.alert.defaultStyle, screen, true) | |
end) | |
end | |
function screenMode:exited() | |
hs.fnutils.ieach(alertUuids, function(uuid) | |
hs.alert.closeSpecific(uuid) | |
end) | |
end | |
grid = { | |
{ key='j', unit=hs.geometry.rect(0, 0.5, 1, 0.5) }, | |
{ key='k', unit=hs.geometry.rect(0, 0, 1, 0.5) }, | |
{ key='h', unit=hs.layout.left50 }, | |
{ key='l', unit=hs.layout.right50 }, | |
{ key='y', unit=hs.geometry.rect(0, 0, 0.5, 0.5) }, | |
{ key='u', unit=hs.geometry.rect(0.5, 0, 0.5, 0.5) }, | |
{ key='b', unit=hs.geometry.rect(0, 0.5, 0.5, 0.5) }, | |
{ key='n', unit=hs.geometry.rect(0.5, 0.5, 0.5, 0.5) }, | |
{ key='space', unit=hs.layout.maximized }, | |
} | |
hs.fnutils.each(grid, function(entry) | |
screenMode:bind('', entry.key, function() | |
hs.window.focusedWindow():moveToUnit(entry.unit) | |
screenMode:exit() | |
end) | |
end) | |
screenMode:bind('ctrl', '[', function() screenMode:exit() end) | |
screenMode:bind('', 'escape', function() screenMode:exit() end) | |
screenMode:bind('cmd', 'h', function() | |
hs.window.focusedWindow():moveOneScreenWest() | |
screenMode:exit() | |
end) | |
screenMode:bind('cmd', 'l', function() | |
hs.window.focusedWindow():moveOneScreenEast() | |
screenMode:exit() | |
end) | |
screenMode:bind('cmd', 'm', function() end) | |
-- Shortcut to reload config | |
ofun = function() | |
hs.reload(j) | |
hs.alert.show("Config loaded") | |
k.triggered = true | |
end | |
k:bind({}, 'r', nil, ofun) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment