-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamethyst-to-goku.js
executable file
·48 lines (37 loc) · 1.11 KB
/
amethyst-to-goku.js
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
#!/usr/bin/env node
// convert ~/.amethyst json to goku keybind format so we can bind with a single key rather than multiple
const json = require("./amethyst.json");
const keybinds = { mod1: [], mod2: [] };
// map amethyst.json key to karabiner/goku key_code.
const symbols = {
",": "comma",
".": "period",
enter: "return_or_enter",
space: "spacebar",
left: "left_arrow",
right: "right_arrow"
};
for (const [name, kb] of Object.entries(json)) {
if (!kb.mod || !kb.key) continue; // not a keybind.
keybinds[kb.mod].push({ name, key: symbols[kb.key] || kb.key });
}
const toGoku = (binds, shortcut) =>
binds
.map(kb => ` [:${kb.key} [:${shortcut}${kb.key}]] ;; ${kb.name}`)
.join("\n");
// remove x=>x mappings
const notSelf = (xs, not) => xs.filter(x => x.key !== not);
const mod1 = toGoku(notSelf(keybinds.mod1, "a"), "!OS");
const mod2 = toGoku(notSelf(keybinds.mod2, "s"), "!OST");
console.log(`
{:des "amethyst mod1 mode"
:rules [:amethyst-mod1-mode
${mod1}
]
}`);
console.log(`
{:des "amethyst mod2 mode"
:rules [:amethyst-mod2-mode
${mod2}
]
}`);