Skip to content

Instantly share code, notes, and snippets.

@jamesgecko
Created August 10, 2017 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesgecko/868da9b122d1cc6703d85b8ec616aea3 to your computer and use it in GitHub Desktop.
Save jamesgecko/868da9b122d1cc6703d85b8ec616aea3 to your computer and use it in GitHub Desktop.
hammerspoon config
-- Tap caps lock for esc, use caps lock with another key for ctrl.
send_escape = false
last_mods = {}
control_key_handler = function()
send_escape = false
end
control_key_timer = hs.timer.delayed.new(0.15, control_key_handler)
control_handler = function(evt)
local new_mods = evt:getFlags()
if last_mods["ctrl"] == new_mods["ctrl"] then
return false
end
if not last_mods["ctrl"] then
last_mods = new_mods
send_escape = true
control_key_timer:start()
else
if send_escape then
hs.eventtap.keyStroke({}, "ESCAPE")
end
last_mods = new_mods
control_key_timer:stop()
end
return false
end
control_tap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged}, control_handler)
control_tap:start()
other_handler = function(evt)
send_escape = false
return false
end
other_tap = hs.eventtap.new({hs.eventtap.event.types.keyDown}, other_handler)
other_tap:start()
-- Open/Toggle applications -----------------------
function toggle_app(name)
local client = hs.application.get(name)
if client == nil then
client = hs.application.open(name)
client:hide()
end
if not client:isFrontmost() then
client:activate()
elseif client:isFrontmost() then
client:hide()
end
end
-- Toggle email window
function toggle_email()
toggle_app("Nylas Mail")
end
hs.hotkey.bind({"cmd", "shift"}, "m", toggle_email)
-- Toggle Slack window
function toggle_slack()
toggle_app("Slack")
end
hs.hotkey.bind({"cmd", "shift"}, "s", toggle_slack)
-- Toggle Github window
function toggle_github()
toggle_app("GitHub Desktop")
end
hs.hotkey.bind({"cmd", "shift"}, "g", toggle_github)
-- Reload config
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
hs.reload()
end)
hs.alert.show("Config loaded")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment