forked from tabrat/talon_user
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstd.py
290 lines (262 loc) · 7.68 KB
/
std.py
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
from talon.voice import Word, Context, Key, Rep, Str, press
from talon import ctrl
import string
# If you're used to VC alphabet, use the line below instead
#alpha_alt = 'arch brov char dell etch fomp goof hark ice jinks koop lug mowsh nerb ork pooch quash rosh souk teek unks verge womp trex yang zooch'.split()
alpha_alt = 'ace bat seek die each fomp gone harm ice jinks kate ella emma near odd pit quest rick sun teeth urge vest whale box yang sap'.split()
#alpha_alt = 'air bat cap die each fail gone harm sit jinks crash look mad near odd pit quest red sun trap urge vest whale box yang sap'.split()
alnum = list(zip(alpha_alt, string.ascii_lowercase)) + \
[(str(i), str(i)) for i in range(0, 10)]
alpha = {}
alpha.update(dict(alnum))
alpha.update({'ship %s' % word: letter for word,
letter in zip(alpha_alt, string.ascii_uppercase)})
alpha.update({'troll %s' % k: Key('ctrl-%s' % v) for k, v in alnum})
alpha.update({'chom %s' % k: Key('cmd-%s' % v) for k, v in alnum})
alpha.update({'command shift %s' % k: Key('ctrl-shift-%s' % v)
for k, v in alnum})
alpha.update({'alt %s' % k: Key('alt-%s' % v) for k, v in alnum})
mapping = {
'semicolon': ';',
r'new-line': '\n',
r'new-paragraph': '\n\n',
}
token_replace = {
'bite': 'byte',
'bites': 'bytes',
'cuba': 'kubectl',
'cutie': 'kubernetes',
'doctor': 'docker',
'i\\pronoun': 'I',
'i\'m': 'I\'m',
'i\'ve': 'I\'ve',
'i\'d': 'I\'d',
'lenox': 'linux',
'neil': 'nil',
'jot': 'jwt',
'jott': 'jwt',
'jason': 'json',
'route': 'root',
}
def parse_word(word):
word = token_replace.get(word, word)
word = word.lstrip('\\').split('\\', 1)[0]
word = mapping.get(word, word)
return word
def text(m):
tmp = [str(s).lower() for s in m.dgndictation[0]._words]
words = [parse_word(word) for word in tmp]
Str(' '.join(words))(None)
def word(m):
tmp = [str(s).lower() for s in m.dgnwords[0]._words]
words = [parse_word(word) for word in tmp]
Str(' '.join(words))(None)
def surround(by):
l = len(by)
if l == 1:
start = by
end = by
elif l % 2 == 0:
m = int(l/2)
start = by[:m]
end = by[m:]
else:
raise Exception('%s bad input for surround' % by)
def func(i, word, last):
if i == 0:
word = start + word
if last:
word += end
return word
return func
def rot13(i, word, _):
out = ''
for c in word.lower():
if c in string.ascii_lowercase:
c = chr((((ord(c) - ord('a')) + 13) % 26) + ord('a'))
out += c
return out
formatters = {
'dunder': (True, lambda i, word, _: '__%s__' % word if i == 0 else word, 0),
'cram': (True, lambda i, word, _: word if i == 0 else word.capitalize(), 0),
'pathway': (True, lambda i, word, _: word if i == 0 else '/'+word, 0),
'dotsway': (True, lambda i, word, _: word if i == 0 else '.'+word, 0),
'snake': (True, lambda i, word, _: word if i == 0 else '_'+word, 0),
'yellsmash': (True, lambda i, word, _: word.upper(), 0),
'yellsnik': (True, lambda i, word, _: word.upper() if i == 0 else '_'+word.upper(), 0),
'smash': (True, lambda i, word, _: word, 0),
'dollcram': (True, lambda i, word, _: '$'+word if i == 0 else word.capitalize(), 0),
'champ': (True, lambda i, word, _: word.capitalize() if i == 0 else " "+word, 0),
'lowcram': (True, lambda i, word, _: '@'+word if i == 0 else word.capitalize(), 0),
'criff': (True, lambda i, word, _: word.capitalize(), 0),
'spine': (True, lambda i, word, _: word if i == 0 else '-'+word, 0),
'title': (False, lambda i, word, _: word.capitalize(), 0),
'yeller': (False, lambda i, word, _: word.upper(), 0),
}
def FormatText(m):
fmt = []
for w in m._words:
if isinstance(w, Word):
fmt.append(w.word)
try:
words = [str(s).lower() for s in m.dgndictation[0]._words]
except AttributeError:
words = [""]
tmp = []
spaces = True
move_left = 0
for i, word in enumerate(words):
word = parse_word(word)
for name in reversed(fmt):
smash, func, move_left = formatters[name]
word = func(i, word, i == len(words)-1)
spaces = spaces and not smash
tmp.append(word)
words = tmp
sep = ' '
if not spaces:
sep = ''
Str(sep.join(words))(None)
while move_left > 0:
press('left')
move_left -= 1
def ShrinkWord(m):
word = str(m.dgndictation[0]._words[0]).lower()
if not word in shrink_map:
raise Exception('%s not in shrink map' % word)
Str(shrink_map[word])(None)
shrink_map = {
'address': 'addr',
'addresses': 'addrs',
'boolean': 'bool',
'compare': 'cmp',
'config': 'cfg',
'context': 'ctx',
'delete': 'del',
'error': 'err',
'errors': 'errs',
'ever': 'err',
'format': 'fmt',
'message': 'msg',
'package': 'pkg',
'parameter': 'param',
'pointer': 'ptr',
'private': 'priv',
'response': 'res',
'user': 'usr',
'userid': 'uid',
'username': 'uname',
'administrator': "admin",
'administrators': "admins",
'allocate': "alloc",
'alternate': "alt",
'apartment': "apt",
'application': "app",
'applications': "apps",
'architecture': "arch",
'argument': "arg",
'arguments': "args",
'attribute': "attr",
'attributes': "attrs",
'authentic': "auth",
'authenticate': "auth",
'author': "auth",
'binary': "bin",
'button': "btn",
'calculate': "calc",
'call': "col",
'car': "char",
'care': "char",
'certificate': "crt",
'character': "char",
'column': "col",
'command': "cmd",
'concatenate': "concat",
'configuration': "config",
'configure': "config",
'constant': "const",
'define': "def",
'descending': "desc",
'develop': "dev",
'developer': "dev",
'development': "dev",
'directory': "dir",
'divider': "div",
'document': "doc",
'environment': "env",
'execute': "exec",
'extend': "ext",
'extension': "ext",
'favorite': "fav",
'function': "func",
'image': "img",
'imager': "int",
'incorporate': "inc",
'increment': "inc",
'initialize': "init",
'integer': "int",
'iterate': "iter",
'jason': "json",
'language': "lang",
'large': "lg",
'latitude': "lat",
'length': "len",
'library': "lib",
'locate': "loc",
'location': "loc",
'longitude': "lng",
'medium': "md",
'minimum': "min",
'miscellaneous': "misc",
'navigate': "nav",
'navigation': "nav",
'number': "num",
'object': "obj",
'parameter': "param",
'parameters': "params",
'position': "pos",
'previous': "prev",
'production': "prod",
'pseudo': "sudo",
'reference': "ref",
'references': "refs",
'repeat': "rep",
'request': "req",
'result': "res",
'revision': "rev",
'source': "src",
'standard': "std",
'standing': "stdin",
'standout': "stdout",
'string': "str",
'system': "sys",
'temporary': "tmp",
'text': "txt",
'thanks': "thx",
'utilities': "utils",
'utility': "util",
'value': "val",
'variable': "var",
# months
'january': "jan",
'february': "feb",
'march': "mar",
'april': "apr",
'june': "jun",
'july': "jul",
'august': "aug",
'september': "sept",
'october': "oct",
'november': "nov",
'december': "dec",
}
ctx = Context('input')
keymap = {}
keymap.update(alpha)
keymap.update({
'say <dgndictation> [over]': text,
'shrink <dgndictation>': ShrinkWord,
'word <dgnwords>': word,
'(%s)+ [<dgndictation>]' % (' | '.join(formatters)): FormatText,
})
ctx.keymap(keymap)