-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.xonshrc
342 lines (276 loc) · 11.5 KB
/
.xonshrc
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# -- modules
import os
import shlex
import json
import subprocess
from datetime import datetime
from uuid import UUID
from argparse import ArgumentParser
from typing import List
from pygments import highlight, formatters, lexers
from pygments.token import (Comment, Error, Generic, Name, Number, Operator, String, Text, Whitespace, Keyword, Literal, Other, Punctuation)
from xonsh.tools import unthreadable
from xonsh.events import events
from xonsh.built_ins import XSH
from xonsh.pyghooks import register_custom_pygments_style
from xonsh.ansi_colors import register_custom_ansi_style
# -- XONTRIB
if XSH.env.get('FORMATTER_DICT') is None:
XSH.env['FORMATTER_DICT'] = {}
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
XSH.builtins.execx('xontrib load zoxide argcomplete coreutils fzf-completions jedi vox')
XSH.env['PROMPT'] = '{env_name}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{branch_color}{curr_branch: {}}{RESET} {BOLD_BLUE}{prompt_end}{RESET} '
XSH.env['GIT_EXTERNAL_DIFF'] = 'difft'
XSH.env['fzf_history_binding'] = "c-r" # Ctrl+R
XSH.env['fzf_ssh_binding'] = "c-s" # Ctrl+S
XSH.env['fzf_file_binding'] = "c-t" # Ctrl+T
XSH.env['fzf_dir_binding'] = "c-g" # Ctrl+G
# The SQLite history backend saves command immediately
# unlike JSON backend that save the commands at the end of the session.
XSH.env['XONSH_HISTORY_BACKEND'] = 'sqlite'
# What commands are saved to the history list. By default all commands are saved.
# * The option ‘ignoredups’ will not save the command if it matches the previous command.
# * The option `erasedups` will remove all previous commands that matches and updates the command frequency.
# The minus of `erasedups` is that the history of every session becomes unrepeatable
# because it will have a lack of the command you repeat in another session.
# Docs: https://xonsh.github.io/envvars.html#histcontrol
XSH.env['HISTCONTROL'] = 'ignoredups'
# Remove front dot in multiline input to make the code copy-pastable.
XSH.env['MULTILINE_PROMPT'] = ' '
# Avoid typing cd just directory path.
# Docs: https://xonsh.github.io/envvars.html#auto-cd
XSH.env['AUTO_CD'] = True
def _default_json_encoder(obj):
if isinstance(obj, bytes):
return '<' + obj.hex() + '>'
if isinstance(obj, datetime):
return str(obj)
if isinstance(obj, UUID):
return str(obj)
raise TypeError()
def _pretty_json(buf, colored=True, default=_default_json_encoder):
formatted_json = json.dumps(buf, sort_keys=True, indent=4, default=default)
if colored:
return highlight(formatted_json, lexers.JsonLexer(), formatters.TerminalTrueColorFormatter(style='stata-dark'))
else:
return formatted_json
def _subprocess(args: List[str]) -> None:
subprocess.Popen(args, shell=True)
@unthreadable
def _ggpush(args):
XSH.builtins.execx(f'git push origin {XSH.env["PROMPT_FIELDS"]["curr_branch"]()} {shlex.join(args)}')
@events.on_chdir
def handler_chdir(olddir, newdir, **kw):
"""
Event handler that updates the prompt when the directory changes
"""
print(f'\033]9;9;{newdir}\033\\\033[A', end='')
# -- STYLE
ANSI_STYLE = {
'BLACK': '#282828', 'BLUE': '#458588', 'CYAN': '#689D6A', 'DEFAULT': '#D4EB98', 'GREEN': '#98971A', 'ORANGE': '#D65D0E', 'PURPLE': '#b16286', 'RED': '#CC441D', 'WHITE': '#EBDBB2', 'YELLOW': '#D79921',
'INTENSE_BLACK': '#665C54', 'INTENSE_BLUE': '#83A598', 'INTENSE_CYAN': '#8EC07C', 'INTENSE_GREEN': '#b8bb26', 'INTENSE_ORANGE': '#fe8019', 'INTENSE_PURPLE': '#D3869B', 'INTENSE_RED': '#fb4934', 'INTENSE_WHITE': '#FBF1F7', 'INTENSE_YELLOW': '#FA8D2F',
}
BG_COLOR = ANSI_STYLE['BLACK']
PG_STYLE = {
Comment: f'{ANSI_STYLE["INTENSE_CYAN"]} italic',
Error: f'{ANSI_STYLE["RED"]} bold',
Generic: f'{ANSI_STYLE["DEFAULT"]}',
Generic.Deleted: f'{ANSI_STYLE["INTENSE_BLACK"]}',
Generic.Emph: f'{ANSI_STYLE["WHITE"]}',
Generic.Error: f'{ANSI_STYLE["RED"]} bold',
Generic.Heading: f'{ANSI_STYLE["INTENSE_WHITE"]}',
Generic.Inserted: f'{ANSI_STYLE["INTENSE_WHITE"]}',
Generic.Output: '#44475A',
Generic.Prompt: f'{ANSI_STYLE["WHITE"]}',
Generic.Strong: f'{ANSI_STYLE["WHITE"]} bold',
Generic.Subheading: f'{ANSI_STYLE["INTENSE_WHITE"]}',
Generic.Traceback: f'{ANSI_STYLE["ORANGE"]}',
Keyword: f'{ANSI_STYLE["INTENSE_RED"]}',
Keyword.Content: f'{ANSI_STYLE["INTENSE_RED"]}',
Keyword.Declaration: f'{ANSI_STYLE["INTENSE_RED"]}',
Keyword.Namespace: f'{ANSI_STYLE["RED"]} bold',
Keyword.Pseudo: f'{ANSI_STYLE["INTENSE_RED"]}',
Keyword.Reserved: f'{ANSI_STYLE["INTENSE_CYAN"]}',
Keyword.Type: f'{ANSI_STYLE["YELLOW"]}',
Literal: f'{ANSI_STYLE["INTENSE_WHITE"]}',
Literal.Date: f'{ANSI_STYLE["INTENSE_WHITE"]}',
Name: f'{ANSI_STYLE["INTENSE_BLUE"]}',
Name.Attribute: f'{ANSI_STYLE["INTENSE_CYAN"]}',
Name.Builtin: f'{ANSI_STYLE["INTENSE_YELLOW"]} bold',
Name.Builtin.Pseudo: f'{ANSI_STYLE["INTENSE_ORANGE"]}',
Name.Class: f'{ANSI_STYLE["INTENSE_ORANGE"]} underline',
Name.Constant: f'{ANSI_STYLE["PURPLE"]}',
Name.Decorator: f'{ANSI_STYLE["INTENSE_RED"]}',
Name.Entity: f'{ANSI_STYLE["INTENSE_WHITE"]}',
Name.Exception: f'{ANSI_STYLE["INTENSE_PURPLE"]}',
Name.Function: f'{ANSI_STYLE["INTENSE_CYAN"]} bold',
Name.Label: f'{ANSI_STYLE["INTENSE_RED"]}',
Name.Namespace: f'{ANSI_STYLE["INTENSE_GREEN"]}',
Name.Other: f'{ANSI_STYLE["WHITE"]}',
Name.Variable: f'{ANSI_STYLE["WHITE"]}',
Name.Variable.Class: f'{ANSI_STYLE["BLUE"]} italic',
Name.Variable.Global: f'{ANSI_STYLE["BLUE"]} italic',
Name.Variable.Instance: f'{ANSI_STYLE["BLUE"]} italic',
Number: f'{ANSI_STYLE["INTENSE_PURPLE"]}',
Operator: f'{ANSI_STYLE["WHITE"]}',
Operator.Word: f'{ANSI_STYLE["RED"]}',
Other: ANSI_STYLE['WHITE'],
Punctuation: ANSI_STYLE['WHITE'],
String: f'{ANSI_STYLE["INTENSE_GREEN"]}',
Text: f'{ANSI_STYLE["WHITE"]}',
Whitespace: f'{ANSI_STYLE["WHITE"]}',
}
register_custom_pygments_style('doronz', PG_STYLE, background_color=BG_COLOR)
register_custom_ansi_style('doronz', ANSI_STYLE)
XSH.env['XONSH_COLOR_STYLE'] = 'doronz'
# -- env
XSH.env['PIP_BREAK_SYSTEM_PACKAGES'] = 1
XSH.env['WORKSETUP_ROOT'] = '~/dev'
for path in (r'C:\Program Files (x86)\GnuWin32\bin', ):
if path not in XSH.env['PATH']:
XSH.env['PATH'].insert(0, path)
# -- ALIAS
def _rcpull(args):
parser = ArgumentParser(description='pull latest .xonshrc')
args = parser.parse_args(args)
cd $WORKSETUP_ROOT/windowssetup
ggpull
cp .xonshrc ~/
cd -
def _rcpush(args):
parser = ArgumentParser(description='push latest .xonshrc')
args = parser.parse_args(args)
cd $WORKSETUP_ROOT/worksetup
cp ~/.xonshrc .
ga .xonshrc
git commit -m 'update .xonshrc'
ggpush
cd -
def _pycharm(args):
if 1 != os.system('where pycharm.rc >nul 2>&1'):
_subprocess(['pycharm.rc', *args])
elif 1 != os.system('where pycharm >nul 2>&1'):
_subprocess(['pycharm', *args])
def _webstorm(args):
if 1 != os.system('where webstorm >nul 2>&1'):
_subprocess(['webstorm', *args])
def _clion(args):
if 1 != os.system('where clion >nul 2>&1'):
_subprocess(['clion', *args])
def _datagrip(args):
if 1 != os.system('where datagrip >nul 2>&1'):
_subprocess(['datagrip', *args])
# -- xonsh
XSH.aliases['open'] = 'explorer'
XSH.aliases['reload'] = 'source ~/.xonshrc'
XSH.aliases['globalrc'] = 'code ~/.xonshrc'
XSH.aliases['rcpull'] = _rcpull
XSH.aliases['rcpush'] = _rcpush
# -- git
XSH.aliases['ga'] = 'git add'
XSH.aliases['ggpush'] = _ggpush
XSH.aliases['gco'] = 'git checkout'
XSH.aliases['ggpull'] = 'git pull'
XSH.aliases['glog'] = 'git log --oneline --decorate --graph'
XSH.aliases['gd'] = 'git diff'
XSH.aliases['gst'] = 'git status'
XSH.aliases['gcl'] = 'git clone --recurse-submodules'
# -- apps
XSH.aliases['ws'] = _webstorm
XSH.aliases['dg'] = _datagrip
XSH.aliases['clion'] = _clion
XSH.aliases['charm'] = _pycharm
# -- shell
XSH.aliases['ls'] = 'coreutils ls -FG'
XSH.aliases['mv'] = 'coreutils mv'
XSH.aliases['tail'] = 'coreutils tail'
XSH.aliases['arch'] = 'coreutils arch'
XSH.aliases['b2sum'] = 'coreutils b2sum'
XSH.aliases['b3sum'] = 'coreutils b3sum'
XSH.aliases['base32'] = 'coreutils base32'
XSH.aliases['base64'] = 'coreutils base64'
XSH.aliases['basename'] = 'coreutils basename'
XSH.aliases['basenc'] = 'coreutils basenc'
XSH.aliases['cat'] = 'coreutils cat'
XSH.aliases['cksum'] = 'coreutils cksum'
XSH.aliases['comm'] = 'coreutils comm'
XSH.aliases['cp'] = 'coreutils cp'
XSH.aliases['csplit'] = 'coreutils csplit'
XSH.aliases['cut'] = 'coreutils cut'
XSH.aliases['date'] = 'coreutils date'
XSH.aliases['dd'] = 'coreutils dd'
XSH.aliases['df'] = 'coreutils df'
XSH.aliases['dircolors'] = 'coreutils dircolors'
XSH.aliases['dirname'] = 'coreutils dirname'
XSH.aliases['du'] = 'coreutils du'
XSH.aliases['echo'] = 'coreutils echo'
XSH.aliases['env'] = 'coreutils env'
XSH.aliases['expand'] = 'coreutils expand'
XSH.aliases['expr'] = 'coreutils expr'
XSH.aliases['factor'] = 'coreutils factor'
XSH.aliases['false'] = 'coreutils false'
XSH.aliases['fmt'] = 'coreutils fmt'
XSH.aliases['fold'] = 'coreutils fold'
XSH.aliases['hashsum'] = 'coreutils hashsum'
XSH.aliases['head'] = 'coreutils head'
XSH.aliases['hostname'] = 'coreutils hostname'
XSH.aliases['join'] = 'coreutils join'
XSH.aliases['link'] = 'coreutils link'
XSH.aliases['ln'] = 'coreutils ln'
XSH.aliases['md5sum'] = 'coreutils md5sum'
XSH.aliases['mkdir'] = 'coreutils mkdir'
XSH.aliases['mktemp'] = 'coreutils mktemp'
XSH.aliases['more'] = 'coreutils more'
XSH.aliases['nl'] = 'coreutils nl'
XSH.aliases['nproc'] = 'coreutils nproc'
XSH.aliases['numfmt'] = 'coreutils numfmt'
XSH.aliases['od'] = 'coreutils od'
XSH.aliases['paste'] = 'coreutils paste'
XSH.aliases['pr'] = 'coreutils pr'
XSH.aliases['printenv'] = 'coreutils printenv'
XSH.aliases['printf'] = 'coreutils printf'
XSH.aliases['ptx'] = 'coreutils ptx'
XSH.aliases['pwd'] = 'coreutils pwd'
XSH.aliases['readlink'] = 'coreutils readlink'
XSH.aliases['realpath'] = 'coreutils realpath'
XSH.aliases['rm'] = 'coreutils rm'
XSH.aliases['rmdir'] = 'coreutils rmdir'
XSH.aliases['seq'] = 'coreutils seq'
XSH.aliases['sha1sum'] = 'coreutils sha1sum'
XSH.aliases['sha224sum'] = 'coreutils sha224sum'
XSH.aliases['sha256sum'] = 'coreutils sha256sum'
XSH.aliases['sha384sum'] = 'coreutils sha384sum'
XSH.aliases['sha3sum'] = 'coreutils sha3sum'
XSH.aliases['sha512sum'] = 'coreutils sha512sum'
XSH.aliases['shake128sum'] = 'coreutils shake128sum'
XSH.aliases['shake256sum'] = 'coreutils shake256sum'
XSH.aliases['shred'] = 'coreutils shred'
XSH.aliases['shuf'] = 'coreutils shuf'
XSH.aliases['sleep'] = 'coreutils sleep'
XSH.aliases['sort'] = 'coreutils sort'
XSH.aliases['split'] = 'coreutils split'
XSH.aliases['sum'] = 'coreutils sum'
XSH.aliases['sync'] = 'coreutils sync'
XSH.aliases['tac'] = 'coreutils tac'
XSH.aliases['tee'] = 'coreutils tee'
XSH.aliases['test'] = 'coreutils test'
XSH.aliases['touch'] = 'coreutils touch'
XSH.aliases['tr'] = 'coreutils tr'
XSH.aliases['true'] = 'coreutils true'
XSH.aliases['truncate'] = 'coreutils truncate'
XSH.aliases['tsort'] = 'coreutils tsort'
XSH.aliases['uname'] = 'coreutils uname'
XSH.aliases['unexpand'] = 'coreutils unexpand'
XSH.aliases['uniq'] = 'coreutils uniq'
XSH.aliases['unlink'] = 'coreutils unlink'
XSH.aliases['vdir'] = 'coreutils vdir'
XSH.aliases['wc'] = 'coreutils wc'
XSH.aliases['whoami'] = 'coreutils whoami'
XSH.aliases['t'] = 'tree'
XSH.aliases['l'] = 'ls -lah'
XSH.aliases['la'] = 'ls -lAh'
XSH.aliases['ll'] = 'ls -lh'
XSH.aliases['lsa'] = 'ls -lah'
XSH.aliases['grt'] = lambda: os.chdir($(git rev-parse --show-toplevel).strip())
XSH.aliases['start'] = 'cmd /c start'