Created
January 25, 2021 02:47
-
-
Save tvhung83/9f8240cb79c066d3b7b4a403c90a5018 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 Hyper Mode | |
k = hs.hotkey.modal.new({}, "F17") | |
-- Trigger existing hyper key shortcuts | |
-- k:bind({}, 'm', nil, function() hs.eventtap.keyStroke({"cmd","alt","shift","ctrl"}, 'm') end) | |
-- OR build your own | |
launch = function(appname) | |
hs.application.launchOrFocus(appname) | |
k.triggered = true | |
end | |
-- Single keybinding for app launch | |
singleapps = { | |
{'i', 'IntelliJ IDEA CE'}, | |
{'c', 'Visual Studio Code - Insiders'}, | |
{'m', 'Mail'}, | |
{'r', 'Slack'}, | |
{'t', 'Microsoft Edge Canary'}, | |
{';', 'iTerm'}, | |
-- {'s', 'Skype'}, | |
{'space', 'Sublime Text'} | |
} | |
for i, app in ipairs(singleapps) do | |
k:bind({}, app[1], function() launch(app[2]); k:exit(); end) | |
end | |
-- Sequential keybindings, e.g. Hyper-a,f for Finder | |
a = hs.hotkey.modal.new({}, "F16") | |
apps = { | |
-- {'d', 'Twitter'}, | |
{'f', 'Finder'}, | |
{'s', 'Skype'}, | |
} | |
for i, app in ipairs(apps) do | |
a:bind({}, app[1], function() launch(app[2]); a:exit(); end) | |
end | |
pressedA = function() a:enter() end | |
releasedA = function() end | |
k:bind({}, 'a', nil, pressedA, releasedA) | |
-- Window Management | |
hs.window.animationDuration = 0 -- disable animations | |
hs.grid.setMargins({0, 0}) | |
hs.grid.setGrid('2x2') | |
local fullScreen = hs.geometry("0,0 2x2") | |
local leftHalf = hs.geometry("0,0 1x2") | |
local rightHalf = hs.geometry("1,0 1x2") | |
local topHalf = hs.geometry("0,0 2x1") | |
local bottomHalf = hs.geometry("0,1 2x1") | |
local upperLeft = hs.geometry("0,0 1x1") | |
local lowerLeft = hs.geometry("0,1 1x1") | |
local upperRight = hs.geometry("1,0 1x1") | |
local lowerRight = hs.geometry("1,1 1x1") | |
k:bind({}, "return", function() hs.grid.set(hs.window.focusedWindow(), fullScreen); k:exit(); end) | |
k:bind({}, "up", function() hs.grid.set(hs.window.focusedWindow(), topHalf); k:exit(); end) | |
k:bind({}, "down", function() hs.grid.set(hs.window.focusedWindow(), bottomHalf); k:exit(); end) | |
k:bind({}, "left", function() hs.grid.set(hs.window.focusedWindow(), leftHalf); k:exit(); end) | |
k:bind({}, "right", function() hs.grid.set(hs.window.focusedWindow(), rightHalf); k:exit(); end) | |
-- Shortcut to reload config | |
ofun = function() | |
hs.reload() | |
hs.alert.show("Config loaded") | |
k.triggered = true | |
end | |
k:bind({}, 'o', nil, ofun) | |
-- Enter Hyper Mode when F18 (Hyper/Capslock) is pressed | |
pressedF18 = function() | |
k.triggered = false | |
k:enter() | |
end | |
-- Leave Hyper Mode when F18 (Hyper/Capslock) is pressed, | |
-- send ESCAPE if no other keys are pressed. | |
releasedF18 = function() | |
k:exit() | |
if not k.triggered then | |
hs.eventtap.keyStroke({}, 'ESCAPE') | |
end | |
end | |
-- Bind the Hyper key | |
f18 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment