forked from dopey/talon_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.py
88 lines (77 loc) · 2.99 KB
/
terminal.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
from talon.voice import Word, Key, Context, Str
import string
terminals = ('com.apple.Terminal', 'com.googlecode.iterm2')
ctx = Context('terminal', func=lambda app, win: any(
t in app.bundle for t in terminals))
mapping = {
'semicolon': ';',
r'new-line': '\n',
r'new-paragraph': '\n\n',
}
def parse_word(word):
word = word.lstrip('\\').split('\\', 1)[0]
word = mapping.get(word, word)
return word
# Ask for forgiveness not permission in failure scenario.
# https://stackoverflow.com/questions/610883/how-to-know-if-an-object-has-an-attribute-in-python
def text(m):
try:
tmp = [str(s).lower() for s in m.dgndictation[0]._words]
words = [parse_word(word) for word in tmp]
Str(' '.join(words))(None)
except AttributeError:
return
keymap = {
'cd': ['cd ; ls', Key('left'), Key('left'), Key('left'), Key('left')],
'(ls | run ellis | run alice)': 'ls\n',
'(la | run la)': 'ls -la\n',
'durrup': 'cd ..; ls\n',
'go back': 'cd -\n',
'pseudo': 'sudo ',
'shell clear': [Key('ctrl-c'), 'clear\n'],
'shell copy [<dgndictation>]': ['cp ', text],
'shell copy curse [<dgndictation>]': ['cp -r', text],
'shell exit': [Key('ctrl-c'), 'exit\n'],
'shell kill': Key('ctrl-c'),
'shell list [<dgndictation>]': ['ls ', text],
'shell list all [<dgndictation>]': ['ls -la ', text],
'shell make (durr | dear) [<dgndictation>]': ['mkdir ', text],
'shell mipple [<dgndictation>]': ['mkdir -p ', text],
'shell move [<dgndictation>]': ['mv ', text],
'shell remove [<dgndictation>]': ['rm ', text],
'shell remove curse [<dgndictation>]': ['rm -rf ', text],
# dep
'dip ensure': 'dep ensure\n',
'dip ensure add': 'dep ensure -add ',
'dip ensure update': 'dep ensure -update\n',
# make
'make': 'make\n',
'make test': 'make test\n',
'make build': 'make build\n',
# git
'jet [<dgndictation>]': ['git ', text],
'jet add [<dgndictation>]': ['git add ', text],
'jet branch': 'git br\n',
'jet branch delete [<dgndictation>]': ['git br -D max/', text],
'jet clone [<dgndictation>]': ['git clone ', text],
'jet checkout master': 'git checkout master\n',
'jet checkout max [<dgndictation>]': ['git checkout max/', text],
'jet checkout [<dgndictation>]': ['git checkout ', text],
'jet checkout branch [<dgndictation>]': ['git checkout -B max/', text],
'jet commit [<dgndictation>]': ['git commit ', text],
'jet diff': 'git diff\n',
'jet history': 'git hist\n',
'jet merge [<dgndictation>]': ['git merge ', text],
'jet pull [<dgndictation>]': ['git pull ', text],
'jet pull base [<dgndictation>]': ['git pull --rebase ', text],
'jet push [<dgndictation>]': ['git push ', text],
'jet rebase': 'git rebase -i HEAD~',
'jet stash': 'git stash\n',
'jet status': 'git status\n',
# Tools
'grip': ['grep .', Key('left left')],
'gripper': ['grep -r .', Key('left left')],
'pee socks': 'ps aux ',
'vi': 'vi ',
}
ctx.keymap(keymap)