-
Notifications
You must be signed in to change notification settings - Fork 1
/
hyper.lua
92 lines (76 loc) · 1.7 KB
/
hyper.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- Hyper keybindings
--
-- Karabiner to bind something (I use right-option) to one of the unused function keys
-- luacheck: globals hs
local M = { hotkeys={} }
M._logger = hs.logger.new("Hyper hotkeys")
local logger = M._logger
logger.i("Loading Hyper hotkeys")
-- # Usage
-- hyper = require('hyper')
-- hyper:start()
HOTKEY = 'F18'
HOTKEY_VIRTUAL = 'F17'
M.hyperMode = hs.hotkey.modal.new({}, HOTKEY_VIRTUAL)
function M.bindKey(mods, key, handler)
M.hyperMode:bind(mods, key, handler)
end
local mods = {'⌃', '⇧', '⌥', '⌘'}
local function combinations(n, p)
if p == 0 then
return {{}}
end
local ii = 1
local combos = {}
local combo = {}
while #combo < p do
if ii <= n then
table.insert(combo, ii)
ii = ii + 1
else
if #combo == 0 then
break
else
ii = table.remove(combo, #combo) + 1
end
end
if #combo == p then
table.insert(combos, {table.unpack(combo)})
ii = table.remove(combo, #combo) + 1
end
end
return combos
end
M.combinations = combinations
local function map(tbl, f)
local t = {}
for k,v in pairs(tbl) do
t[k] = f(v)
end
return t
end
local modifier_combos = {}
for n=0,4 do
for _, v in ipairs(combinations(4, n)) do
-- print(mods[v[1]], mods[v[2]], mods[v[3]])
-- print(table.unpack(v))
table.insert(modifier_combos, map(v, function(x) return mods[x] end))
end
end
function M.enter()
M.hyperMode:enter()
end
function M.exit()
M.hyperMode:exit()
end
function M:start()
for _, mm in ipairs(modifier_combos) do
table.insert(M.hotkeys, hs.hotkey.bind(mm, HOTKEY, M.enter, M.exit))
end
end
function M:stop()
for _, mm in ipairs(M.hotkeys) do
mm:delete()
end
end
return M