-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbind.moon
More file actions
39 lines (27 loc) · 953 Bytes
/
Copy pathbind.moon
File metadata and controls
39 lines (27 loc) · 953 Bytes
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
abutton = require "awful.button"
akey = require "awful.key"
gtable = require "gears.table"
modifiers =
"M": "Mod4"
"A": "Mod1"
"S": "Shift"
"C": "Control"
split = (s, sep)->
sep = sep or "%s"
[m for m in s\gmatch string.format "([^%s]+)", sep]
parse_key = (s)->
res = split s, "-"
[modifiers[k] for k in *res when modifiers[k]], res[#res]
parse_btn = (s)->
if type(s) == "number" then return {}, s
res = split s, "-"
[modifiers[k] for k in *res when modifiers[k]], tonumber res[#res]
mkkey = (keydef, arg)->
mods, key = parse_key keydef
akey mods, key, arg.cb, description: arg.desc, group: arg.group
mkbtn = (btndef, arg)->
mods, btn = parse_btn btndef
abutton mods, btn, arg
keytable = (tbl)-> gtable.join table.unpack [mkkey k, a for k, a in pairs tbl]
btntable = (tbl)-> gtable.join table.unpack [mkbtn b, a for b, a in pairs tbl]
return {:mkkey, :keytable, :mkbtn, :btntable}