Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hammerspoon Config File, Hyper Key, Karabiner-Elements
-- hattip https://github.com/lodestone/hyper-hacks
-- hattip https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907
-- 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','m','a','r','d','g','s','f','TAB','v','b'}
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)
-- vi cursor movement commands
movements = {
{ 'h', {}, 'LEFT'},
{ 'j', {}, 'DOWN'},
{ 'k', {}, 'UP'},
{ 'l', {}, 'RIGHT'},
{ '0', {'cmd'}, 'LEFT'}, -- beginning of line
{ '4', {'cmd'}, 'RIGHT'}, -- end of line
{ 'b', {'alt'}, 'LEFT'}, -- back word
{ 'w', {'alt'}, 'RIGHT'}, -- forward word
}
for i,bnd in ipairs(movements) do
hs.hotkey.bind({'ctrl'}, bnd[1], function()
hs.eventtap.keyStroke(bnd[2],bnd[3])
end)
end
-- Reload config when any lua file in config directory changes
function reloadConfig(files)
doReload = false
for _,file in pairs(files) do
if file:sub(-4) == '.lua' then
doReload = true
end
end
if doReload then
hs.reload()
end
end
local myWatcher = hs.pathwatcher.new(os.getenv('HOME') .. '/.hammerspoon/', reloadConfig):start()
hs.alert.show('Config loaded')
@inoicouldalwaysturn2u

This comment has been minimized.

Copy link

inoicouldalwaysturn2u commented Oct 3, 2016

Thanks for this. Liked seeing a bit of different config here. Get me grokking Hammerspoon and even Lua a bit more.

@theReticent

This comment has been minimized.

Copy link

theReticent commented Oct 21, 2016

Awesome. My muscle memory is thanking you! But isn't there a way to use hjkl with the hyper key instead of control? And this way you have to release ctrl+j after each stroke which is a bit tedious.

@clickysteve

This comment has been minimized.

Copy link

clickysteve commented Oct 28, 2016

Thank you for your work on this! I forked and uploaded my tweaked code for my own setup here:

https://gist.github.com/clickysteve/e13a11b8fc9c963c08b3109d95bbacc5

Gave attribution but not sure of the correct etiquette, so let me know if anything should be revised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.