forked from rmm5t/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd-key-happy.lua
74 lines (64 loc) · 2.21 KB
/
cmd-key-happy.lua
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
-- See https://github.com/aim-stuff/cmd-key-happy
function Set(t)
local s = {}
for _,v in pairs(t) do s[v] = true end
return s
end
function set_contains(t, e)
return t[e]
end
-- The set of global shortcuts we don't want to swap cmd/alt.
global_excludes = Set{ "shift-cmd-tab",
"cmd-tab",
"cmd-space",
"shift-cmd-space",
"cmd-,",
}
-- The set of apps we want to consider swapping keys for, with some
-- notable exclusions. The exclusion means that a "cmd-w" will do the
-- normal OS Terminal behaviour. If you omit items then you would
-- have to use "alt-w" to close a terminal window.
terminal_excludes = Set{ "shift-cmd-[",
"shift-cmd-]",
"cmd-c",
"cmd-v",
"cmd-w",
"cmd-t",
"cmd-n",
"cmd-`",
"cmd-k",
}
apps = {
Terminal = { exclude = terminal_excludes },
iTerm = { exclude = terminal_excludes },
}
-- Return true to swap cmd/alt, otherwise false.
-- This function is passed a table comprising the following keys:
--
-- key_str_seq key sequence (e.g., "shift-cmd-e")
-- alt true if the alt key was pressed
-- fn true if the fn key was pressed
-- control true if the control key was pressed
-- shift true if the shift key was pressed
-- cmd true if the command key was pressed
-- keycode numeric virtual keycode (e.g., 48)
-- appname the frontmost application (e.g., Terminal)
--
-- The order of the modifier keys in key-str-eq is always:
-- shift control alt cmd fn, separated by a hyphen ("-").
function swap_keys(t)
-- for i,v in pairs(t) do print(i,v) end
-- print(t.appname)
if set_contains(global_excludes, t.key_str_seq) then
return false
end
if not apps[t.appname] then
return false
end
local excludes = apps[t.appname]["exclude"]
if set_contains(excludes, t.key_str_seq) then
-- print("exluding: ", t.key_str_seq)
return false
end
return true
end