-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.lua
59 lines (41 loc) · 1.08 KB
/
init.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
local frontmostApplication = require 'hs.application'.frontmostApplication
local modal_new = require 'hs.hotkey'.modal.new
local doAfter = require 'hs.timer'.doAfter
local setup = require 'kit'.setup
local keystroke = require 'ensure/keystroke'
local send = keystroke.send
local _M = {}
_M.config = {
escape = { {}, 'escape' },
message = 'Press again to confirm',
delay = 1,
}
local escape, message, delay
function _M.init(config)
setup(keystroke, config.keystroke)
escape = config.escape
message = config.message
delay = config.delay
end
local function bind(mods, key)
local modal = modal_new(mods, key, message)
local function nay()
modal:exit()
end
local function yay()
send(frontmostApplication(), mods, key)
modal:exit()
end
function modal:entered()
doAfter(delay, nay)
end
modal:bind(escape[1], escape[2], nay)
modal:bind(mods, key, nil, yay)
return modal
end
_M.bind = bind
local function bindSpec(keyspec)
return bind(keyspec[1], keyspec[2])
end
_M.bindSpec = bindSpec
return _M