Last active
October 3, 2024 09:40
-
-
Save kidd/dfd61826803e256d53a9acedeb195fab to your computer and use it in GitHub Desktop.
hammerspoon snippet to c-n,c-p... in slack and chrome
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
local function remap(from_key, to_key) | |
return hs.hotkey.new(from_key[1], from_key[2], | |
function() hs.eventtap.keyStroke(to_key[1], to_key[2]) end) | |
end | |
local maps={} | |
local function remap_add(win_filter_name, from_key, to_key) | |
maps[win_filter_name] = maps[win_filter_name] or {} | |
table.insert(maps[win_filter_name], remap(from_key, to_key)) | |
end | |
local function remap_init() | |
for k, v in pairs(maps) do | |
hs.window.filter.new(k) | |
:subscribe(hs.window.filter.windowFocused, | |
function() | |
for _, v in ipairs(v) do v:enable() end | |
end) | |
:subscribe(hs.window.filter.windowUnfocused, | |
function() | |
for _, v in ipairs(v) do v:disable() end | |
end) | |
end | |
end | |
-- https://www.hammerspoon.org/docs/hs.keycodes.html | |
remap_add("Slack", {{"ctrl"}, "p"},{{}, "up"}) | |
remap_add("Slack", {{"ctrl"}, "n"},{{}, "down"}) | |
remap_add("Slack", {{"alt"}, "b"},{{"alt"}, "left"}) | |
remap_add("Slack", {{"alt"}, "f"},{{"alt"}, "right"}) | |
remap_add("Slack", {{"alt"}, "d"},{{"alt", "shift"}, "forwarddelete"}) | |
remap_add("Chromium", {{"alt"}, "b"},{{"alt"}, "left"}) | |
remap_add("Chromium", {{"alt"}, "f"},{{"alt"}, "right"}) | |
remap_add("Chromium", {{"alt"}, "d"},{{"alt", "shift"}, "forwarddelete"}) | |
remap_init() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment