summaryrefslogtreecommitdiff
path: root/config/hammerspoon/local-example.lua
blob: 19dcc2a2843417ed0881db0f0101cb72687d7ece (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- Example ~/.config/hammerspoon/local.lua: Hammerspoon for one machine only.
--
-- Not linked and never synced -- write it by hand where it is wanted. Only
-- init.lua is linked into ~/.config/hammerspoon, so a file beside it there is
-- the machine's own and in no repo. init.lua loads it last, inside a pcall: it
-- can override anything set there, and a mistake in it is reported without
-- taking the rest of the config down.
--
-- Reload with ctrl-shift-alt-h, as with any other change.
--
-- 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 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', ca, focus("Slack"))

-- Type something only this machine knows about.
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', 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', hyp, function()
    hs.alert.show(hs.host.localizedName())
end)

-- Caps Lock is F20 on every Mac here (see dotlib.capslock_f20, called from
-- init.lua), and nothing is bound to it by default. Give it a job:
hotkey('f20', {}, focus("Ghostty"))

-- Or give the key back on this machine only. A side effect cannot be shadowed
-- the way a hotkey can -- the remap has already happened by the time this file
-- loads -- so there is a function for it, which also clears the live mapping.
-- lib.capslock_off()