all repos — dot @ f31a7a6d69713d45463d53765c9e39aa06290f8c

Shell, editor and terminal configuration, and the tools that go with them

hammerspoon: the example's header is init.lua's, so bindings move either way

It unpacked only hotkey and mods, so a line copied from init.lua -- which
writes `hotkey('9', csa, type_text(...))` with bare names -- did not run here,
and a line moved the other way had to be rewritten. The header is now the same
block init.lua has, name for name, and the examples use the bare names too.

Unused names in it are harmless, and keeping them whole is the point: paste a
binding in either direction and it works as written.
Igor Soarez igor@soarez.org
Mon, 21 Sep 2026 18:53:13 +0300
commit

f31a7a6d69713d45463d53765c9e39aa06290f8c

parent

94a8f1ff31a804a4dfa46ce287e30bf4691ae637

1 files changed, 21 insertions(+), 8 deletions(-)

jump to
M config/hammerspoon/local-example.lua → config/hammerspoon/local-example.lua

@@ -8,25 +8,38 @@ -- taking the rest of the config down.

-- -- Reload with ctrl-shift-alt-h, as with any other change. -- --- The helpers init.lua uses are in dotlib.lua, linked beside it, so this file --- calls them the same way it does: hotkey(key, mods, fn), the mod tables, and --- focus/execute/type_text. hs.* is available too, for anything not in there. +-- The helpers are in dotlib.lua, linked beside init.lua. This header is the +-- same one init.lua has, names included, so a binding can be moved between the +-- two files unchanged -- which is how a machine takes something out of the +-- shared config, or the shared config adopts something that started here. +-- Anything not in the module is still reachable as hs.*. local lib = require("dotlib") -local hotkey, mods = lib.hotkey, lib.mods + +local focus = lib.focus +local execute = lib.execute +local hotkey = lib.hotkey +local type_text = lib.type_text +local type_current_date = lib.type_current_date +local type_random_ids = lib.type_random_ids +local cs, ca, csa = lib.mods.cs, lib.mods.ca, lib.mods.csa +local cag, hyp, spc = lib.mods.cag, lib.mods.hyp, lib.mods.spc -- Take a key over. Binding a combination init.lua already bound wins, because -- hs.hotkey stacks bindings per combination and this one is enabled last. -hotkey('1', mods.ca, lib.focus("Slack")) +hotkey('1', ca, focus("Slack")) -- Type something only this machine knows about. -hotkey('9', mods.csa, lib.type_text('someone@example.com')) +hotkey('9', csa, type_text('someone@example.com')) -- Give a key back to the OS or another app: bind it to nothing. A binding from -- init.lua cannot be deleted from here -- it keeps no reference to the hotkey -- object -- so shadowing it with a no-op is how it is switched off. -hotkey('0', mods.cag, function() end) +hotkey('0', cag, function() end) + +-- spc is a key, not a modifier set: it goes in the first argument. +hotkey(spc, cs, execute('open -a Finder')) -- Anything else Hammerspoon can do belongs here just as well. -hotkey('m', mods.ca, function() +hotkey('m', hyp, function() hs.alert.show(hs.host.localizedName()) end)