Last active
February 27, 2024 20:28
-
-
Save rednebmas/367ea32a14167e1c24301c2fa509cd0b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
local function pressFn(mods, key) | |
if key == nil then | |
key = mods | |
mods = {} | |
end | |
return function() hs.eventtap.keyStroke(mods, key, 10) end | |
end | |
local function remap(mods, key, pressFn) | |
hs.hotkey.bind(mods, key, pressFn, nil, pressFn) | |
end | |
local function remap_unbound(mods, key, pressFn) | |
return hs.hotkey.new(mods, key, pressFn, nil, pressFn) | |
end | |
-- Move | |
remap({'ctrl'}, 'h', pressFn('left')) | |
remap({'ctrl'}, 'j', pressFn('down')) | |
remap({'ctrl'}, 'k', upOrIMessageEditFN()) | |
remap({'ctrl'}, 'l', pressFn('right')) | |
-- Select and move | |
remap({'ctrl', 'shift'}, 'h', pressFn({'shift'}, 'left')) | |
remap({'ctrl', 'shift'}, 'j', pressFn({'shift'}, 'down')) | |
remap({'ctrl', 'shift'}, 'k', pressFn({'shift'}, 'up')) | |
remap({'ctrl', 'shift'}, 'l', pressFn({'shift'}, 'right')) | |
-- Jump by word move | |
remap({'alt'}, 'h', pressFn({'alt'}, 'left')) | |
remap({'alt'}, 'l', pressFn({'alt'}, 'right')) | |
-- Jump by word select | |
remap({'alt', 'shift'}, 'h', pressFn({'alt', 'shift'}, 'left')) | |
remap({'alt', 'shift'}, 'l', pressFn({'alt', 'shift'}, 'right')) | |
-- | |
-- Switch tab hotkeys | |
-- | |
-- right | |
hs.hotkey.bind({'cmd', 'shift'}, 'l', function() | |
if hs.application.frontmostApplication():title() == 'Xcode' then | |
pressFn({'cmd', 'shift'}, ']')() | |
elseif hs.application.frontmostApplication():title() == 'Terminal' then | |
pressFn({'cmd', 'shift'}, ']')() | |
elseif hs.application.frontmostApplication():title() == 'Google Chrome' then | |
pressFn({'cmd', 'option'}, 'right')() | |
elseif hs.application.frontmostApplication():title() == 'AppCode' then | |
pressFn({'cmd', 'shift'}, ']')() | |
elseif hs.application.frontmostApplication():title() == 'Code' then | |
pressFn({'cmd', 'shift'}, ']')() | |
else | |
pressFn({'cmd', 'shift'}, 'l')() | |
end | |
end) | |
hs.hotkey.bind({'cmd', 'shift'}, 'h', function() | |
if hs.application.frontmostApplication():title() == 'Xcode' then | |
pressFn({'cmd', 'shift'}, '[')() | |
elseif hs.application.frontmostApplication():title() == 'Terminal' then | |
pressFn({'cmd', 'shift'}, '[')() | |
elseif hs.application.frontmostApplication():title() == 'Google Chrome' then | |
pressFn({'cmd', 'option'}, 'left')() | |
elseif hs.application.frontmostApplication():title() == 'AppCode' then | |
pressFn({'cmd', 'shift'}, '[')() | |
elseif hs.application.frontmostApplication():title() == 'Code' then | |
pressFn({'cmd', 'shift'}, '[')() | |
else | |
hs.alert.show('Should have passed through?') | |
hs.timer.doAfter(1000, function() pressFn({'cmd', 'shift'}, 'h')() end) | |
end | |
end) | |
-- | |
-- reload hammerspoon config | |
-- | |
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function() | |
hs.reload() | |
end) | |
hs.alert.show("Config loaded") | |
-- misc | |
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "I", function() | |
hs.alert.show(hs.application.frontmostApplication():title()) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment