forked from evan-liu/karabiner.ts.examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
131 lines (115 loc) · 4.83 KB
/
index.ts
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import {
ifApp,
ifVar,
layer,
map,
mapDoubleTap,
NumberKeyValue,
rule,
simlayer,
withCondition,
withMapper,
writeToProfile,
} from 'karabiner.ts'
// ! Change '--dry-run' to your Karabiner-Elements Profile name.
// (--dry-run print the config json into console)
// + Create a new profile if needed.
writeToProfile('--dry-run', [
// It is not required, but recommended to put symbol alias to layers,
// to make it easier to write '←' instead of 'left_arrow'.
// Supported alias: https://github.com/evan-liu/karabiner.ts/blob/main/src/utils/key-alias.ts
layer('/', 'symbol-mode').manipulators([
// / + [ 1 2 3 4 5 ] =>
withMapper(['⌘', '⌥', '⌃', '⇧', '⇪'])((k, i) =>
map((i + 1) as NumberKeyValue).toPaste(k),
),
withMapper(['←', '→', '↑', '↓', '␣', '⏎', '⇥', '⎋', '⌫', '⌦', '⇪'])((k) =>
map(k).toPaste(k),
),
]),
// If you type fast, use simlayer instead, see https://github.com/yqrashawn/GokuRakuJoudo/blob/master/tutorial.md#simlayers
simlayer('z', 'emoji-mode').manipulators([
map('m').toPaste('🔀'), // Merge branches
]),
// In Karabiner-Elements a 'rule' is a group of manipulators.
// layer() and simlayer() are extended rule().
rule('Shell command').manipulators([
// Use to$() to run a shell command
map('⎋', 'Hyper').to$('rm -rf ~/wip'),
// toApp() is shortcut for to$('open -a {app}.app')
map('f', 'Meh').toApp('Finder'),
]),
// There are multiple ways of using modifiers
rule('Modifiers').manipulators([
// You can use their key_code
map('a', ['left_command', 'left_option']).to('b', ['fn']),
// Or alias (easier to write if mapped to a layer)
map('a', { left: '⌘⌥' }).to('b', 'fn'),
// Or if it can be either left or right side:
map('a', '⌘⌥').to('b', 'fn'),
// 'Hyper' is ⌘⌥⌃⇧ and 'Meh' is ⌥⌃⇧
// ⚠️ Note: Modifier alias (command|option|control|shift and ⌘⌥⌃⇧)
// can only be used as modifiers, but not as key_code
map('right_command').toHyper(),
map('⇪').toMeh().toIfAlone('⇪'),
map('a', 'Hyper').to('b', 'Meh'),
// Add optional modifiers after the mandatory modifiers. About optional modifiers:
// https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/from/modifiers/#frommodifiersoptional
map('a', '⌘', 'any').to('b'), // ⌘⇧a -> ⇧b
]),
// Rules can have conditions which will be added to all manipulators.
rule('Conditions', ifApp('^com.apple.finder$')).manipulators([
// manipulators can also have multiple conditions
// layer/simlayer are behind a 'variable_if' condition.
// use unless() to switch {condition}_if to {condition}_unless
map(0).to(1).condition(ifVar('vi-mode'), ifVar('stop').unless()),
]),
// Optional parameters can be set when use
// - from.simultaneous - basic.simultaneous_threshold_milliseconds
// - to_if_alone - basic.to_if_alone_timeout_milliseconds
// - to_if_held_down - basic.to_if_held_down_threshold_milliseconds
// - to_delayed_action - basic.to_delayed_action_delay_milliseconds
rule('Parameters').manipulators([
map('left_option')
.toIfAlone('r', '⌘')
.parameters({ 'basic.to_if_alone_timeout_milliseconds': 500 }),
]),
// There are some other useful abstractions over the json config.
// [File an issue](https://github.com/evan-liu/karabiner.ts/issues) to suggest more.
rule('Other abstractions').manipulators([
// Move the mouse cursor to a position and (optionally) to a screen.
map('↑', 'Meh').toMouseCursorPosition({ x: '100%', y: 0 }),
map('→', 'Meh').toMouseCursorPosition({ x: '50%', y: '50%', screen: 1 }),
]),
// There are also some useful utilities
rule('Utility').manipulators([
// For nested conditions inside rules/layers
map(0).to(1).condition(ifVar('a')),
// You can group them using withCondition()
withCondition(ifVar('a'))([
map(0).to(1),
map(1).to(2).condition(ifApp('X').unless()), // And nest more conditions.
]),
// Use withMapper() to apply the same mapping
withMapper({ c: 'Calendar', f: 'Finder' })((k, v) =>
map(k, 'Meh').toApp(v),
),
// And some others like double-tap
mapDoubleTap(1).to('w', '⌘'),
]),
])
/*
Karabiner-Elements profile parameters can also be set by the 3rd parameter
of writeToProfile('profileName', [ rules ], { params }). The default values are:
// Karabiner-Elements parameters
'basic.to_if_alone_timeout_milliseconds': 1000,
'basic.to_if_held_down_threshold_milliseconds': 500,
'basic.to_delayed_action_delay_milliseconds': 500,
'basic.simultaneous_threshold_milliseconds': 50,
'mouse_motion_to_scroll.speed': 100,
// karabiner.ts only parameters
// for simlayer()
'simlayer.threshold_milliseconds': 200
// for mapDoubleTap()
'double_tap.delay_milliseconds': 200,
*/