Skip to content

Instantly share code, notes, and snippets.

@markx
Created July 12, 2023 05:00
Show Gist options
  • Save markx/6e7c38c56d0eb37188ab1ad831a73ee2 to your computer and use it in GitHub Desktop.
Save markx/6e7c38c56d0eb37188ab1ad831a73ee2 to your computer and use it in GitHub Desktop.
hammerspoon for tmux prefix
local apps = {"iTerm2", "Terminal"}
local hyper = {"cmd", "alt", "ctrl", "shift"}
local hotkey = hs.hotkey.new({'ctrl'}, 'tab', function() hs.eventtap.keyStroke({'ctrl'}, 'z') end)
local hotkeys = {
hs.hotkey.new({'ctrl'}, 'tab', function() hs.eventtap.keyStroke({'ctrl'}, 'z') end),
hs.hotkey.new(hyper, 'f', function() hs.eventtap.keyStroke({'ctrl'}, 'z') end),
hs.hotkey.new({'cmd'}, 's', function() hs.eventtap.keyStroke({'ctrl'}, 'z') end),
}
local enable_hotkey_matching_for_app = function(app_names, hotkeys)
app_names = type(app_names) =="table" and app_names or {app_names}
local filter = hs.window.filter.new(app_names)
filter:subscribe(hs.window.filter.windowFocused, function()
for i,hk in ipairs(hotkeys) do
hk:enable()
end
end)
filter:subscribe(hs.window.filter.windowUnfocused, function()
for i,hk in ipairs(hotkeys) do
hk:disable()
end
end)
end
enable_hotkey_matching_for_app(apps, hotkey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment