summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-09-21 18:53:13 +0300
committerIgor Soarez <igor@soarez.org>2026-09-21 18:53:13 +0300
commitf31a7a6d69713d45463d53765c9e39aa06290f8c (patch)
treec62851978653f5141ea3a3094cccf88c838ad892
parent94a8f1ff31a804a4dfa46ce287e30bf4691ae637 (diff)
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.
-rw-r--r--config/hammerspoon/local-example.lua29
1 files changed, 21 insertions, 8 deletions
diff --git a/config/hammerspoon/local-example.lua b/config/hammerspoon/local-example.lua
index cf2963d..967c14e 100644
--- a/config/hammerspoon/local-example.lua
+++ b/config/hammerspoon/local-example.lua
@@ -8,25 +8,38 @@
--
-- 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)