-
Notifications
You must be signed in to change notification settings - Fork 2
/
.xonshrc
269 lines (204 loc) · 8.8 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
# -*-mode: python; flycheck-mode: nil -*-
# Some useful functions to have in the namespace. Anything that needs to be
# imported for utility should be deleted or done inside a function so it
# doesn't clutter up the interactive namespace.
$PATH.insert(0, "/Users/aaronmeurer/anaconda/bin")
from pprint import pprint
try:
from setproctitle import setproctitle
setproctitle('xonsh')
except ImportError:
print("Could not import setproctitle")
##############
# The prompt #
##############
def cwd_dirname():
from os.path import basename
from os import getcwd
try:
cwd = getcwd()
except FileNotFoundError:
return "{BOLD_YELLOW}{BACKGROUND_BLACK}!!Current working directory not found!!{NO_COLOR}".format(**$FORMATTER_DICT)
return basename(getcwd())
$FORMATTER_DICT['cwd_dirname'] = cwd_dirname
$GIT_PS1_SHOWDIRTYSTATE=1
$GIT_PS1_SHOWUNTRACKEDFILES=1
$GIT_PS1_SHOWUPSTREAM="auto"
$GIT_PS1_STATESEPARATOR=''
$LSCOLORS="eAfAcAdAbAegedabagacad"
$CLICOLOR_FORCE=1 # Always use colors with ls, even when piping to less
$TTY=$(basename $(tty))
def git_prompt_bash():
return $(bash -c 'source ~/Documents/git/contrib/completion/git-prompt.sh; __git_ps1 "%s"')
$FORMATTER_DICT['git_prompt_bash'] = git_prompt_bash
$FORMATTER_DICT['CONDA_DEFAULT_ENV'] = lambda: __xonsh_env__.get('CONDA_DEFAULT_ENV', '')
# Color tabs based on directories in iTerm 2
# Colors are done as "\033]6;1;bg;red;brightness;NNN\a\033]6;1;bg;blue;brightness;NNN\a\033]6;1;bg;green;brightness;NNN\a"
# Where you have ^ ^ ^ ^ ^ ^
# | | | | | |
# red------->color value blue------>color value green------->color value
# (0-255) (0-255) (0-255)
# The easiest way to get the color codes for a color is to just type the color
# name into WolframAlpha, and it will just tell you. Or, if you have a
# particular color on-screen that you want, you can use DigitalColor Meter in
# /Applications/Utilities/
# XXX: Make sure the directory names end in /
# sympy - Red
DIR_SYMPY = '/Users/aaronmeurer/Documents/Python/sympy/sympy/'
TAB_RED = "\033]6;1;bg;red;brightness;255\a\033]6;1;bg;blue;brightness;0\a\033]6;1;bg;green;brightness;0\a"
# sympy-scratch - Orange
DIR_SYMPY_SCRATCH = '/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/'
TAB_ORANGE = "\033]6;1;bg;red;brightness;255\a\033]6;1;bg;blue;brightness;0\a\033]6;1;bg;green;brightness;128\a"
# sympy-bot - Purple
DIR_SYMPY_BOT = '/Users/aaronmeurer/Documents/Python/sympy/sympy-bot/'
TAB_PURPLE = "\033]6;1;bg;red;brightness;255\a\033]6;1;bg;blue;brightness;255\a\033]6;1;bg;green;brightness;0\a"
# sympy other (like sympy-live or sympy.wiki) - Yellow
# Note, this one must be tested after the above ones
DIR_SYMPY_OTHER = '/Users/aaronmeurer/Documents/Python/sympy/'
TAB_YELLOW = "\033]6;1;bg;red;brightness;255\a\033]6;1;bg;blue;brightness;0\a\033]6;1;bg;green;brightness;255\a"
# dotfiles - Green
DIR_DOTFILES = '/Users/aaronmeurer/Documents/dotfiles/'
TAB_GREEN = "\033]6;1;bg;red;brightness;0\a\033]6;1;bg;blue;brightness;0\a\033]6;1;bg;green;brightness;255\a"
# Continuum - Black
DIR_CONTINUUM = '/Users/aaronmeurer/Documents/Continuum/'
TAB_BLACK = "\033]6;1;bg;red;brightness;0\a\033]6;1;bg;blue;brightness;0\a\033]6;1;bg;green;brightness;0\a"
# Conda - White
DIR_CONDA = '/Users/aaronmeurer/Documents/Continuum/conda/'
TAB_WHITE = "\033]6;1;bg;red;brightness;255\a\033]6;1;bg;blue;brightness;255\a\033]6;1;bg;green;brightness;255\a"
# Conda-build - Teal
DIR_CONDA_BUILD = '/Users/aaronmeurer/Documents/Continuum/conda-build/'
TAB_TEAL = "\033]6;1;bg;red;brightness;0\a\033]6;1;bg;blue;brightness;128\a\033]6;1;bg;green;brightness;128\a"
# Blog - Teal
DIR_BLOG = '/Users/aaronmeurer/Documents/blog/'
# homework - Blue
DIR_HOMEWORK = "/Users/aaronmeurer/Documents/Homework/Grad/Fall 2013/"
TAB_BLUE = "\033]6;1;bg;red;brightness;0\a\033]6;1;bg;blue;brightness;255\a\033]6;1;bg;green;brightness;0\a"
# conda-recipes - Purple (defined above)
DIR_CONDA_RECIPES="/Users/aaronmeurer/Documents/Continuum/conda-recipes/"
# Other - default (gray)
# We can't clear the tab, so just match the color of the default tabs.
# (https://gitlab.com/gnachman/iterm2/issues/1904)
TAB_GRAY = "\033]6;1;bg;red;brightness;206\a\033]6;1;bg;blue;brightness;206\a\033]6;1;bg;green;brightness;206\a"
from collections import OrderedDict
DIR_TAB_COLOR = OrderedDict([
(DIR_SYMPY, TAB_RED),
(DIR_SYMPY_SCRATCH, TAB_ORANGE),
(DIR_SYMPY_BOT, TAB_PURPLE),
(DIR_SYMPY_OTHER, TAB_YELLOW),
(DIR_DOTFILES, TAB_GREEN),
(DIR_HOMEWORK, TAB_BLUE),
(DIR_CONDA, TAB_WHITE),
(DIR_CONDA_BUILD, TAB_TEAL),
(DIR_CONDA_RECIPES, TAB_PURPLE),
(DIR_CONTINUUM, TAB_BLACK),
(DIR_BLOG, TAB_TEAL),
])
del OrderedDict
def get_tab_color():
# To make this work correctly with subdirectories, put higher level
# directories later in the list. Hence, we use an OrderedDict
from os import getcwd
try:
cwd = getcwd()
except FileNotFoundError:
return ''
for dir, color in DIR_TAB_COLOR.items():
if (cwd + '/').startswith(dir):
return color
return TAB_GRAY
def set_tab_color():
import sys
sys.stdout.write(get_tab_color())
# Clear cruft from the tab title (http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#s3)
sys.stdout.write("\033]0;\007")
return ''
$FORMATTER_DICT['set_tab_color'] = set_tab_color
def print_carriage_return():
import sys
sys.stdout.write('\r')
return ''
$FORMATTER_DICT['carriage_return'] = print_carriage_return
def iterm2_shell_integration_prompt_command():
return $(bash -c 'source /Users/aaronmeurer/.iterm2_shell_integration.bash; preexec_invoke_cmd')
$FORMATTER_DICT['iterm2_shell_integration_prompt_command'] = iterm2_shell_integration_prompt_command
$PROMPT = '{CONDA_DEFAULT_ENV}{BOLD_WHITE}{BACKGROUND_BLACK}{cwd_dirname}{NO_COLOR}{BOLD_CYAN}{git_prompt_bash}{NO_COLOR}{BACKGROUND_RED}🐚 {NO_COLOR}{set_tab_color}'
###########
# Aliases #
###########
aliases['rm'] = 'rm -i'
aliases['cp'] = 'cp -i'
aliases['mv'] = 'mv -i'
def ssh(args, stdin=None):
$TERM = 'xterm-256color'
ssh @(args) < @(stdin)
aliases['ssh'] = ssh
del ssh
def vagrant(args, stdin=None):
$TERM = 'xterm-256color'
vagrant @(args) < @(stdin)
aliases['vagrant'] = vagrant
del vagrant
aliases['ls'] = 'ls -AG@Flha'
aliases[' l'] = 'ls -AG@Flha'
aliases['grep'] = 'grep -i --color=always'
aliases['mkdir'] = 'mkdir -p'
aliases['cdsympy'] = 'cd ~/Documents/python/sympy/sympy'
aliases['cds'] = 'cd ~/Documents/python/sympy/sympy'
aliases['cdss'] = 'cd ~/Documents/python/sympy/sympy-scratch'
aliases['cdsss'] = 'cd ~/Documents/python/sympy/sympy-scratch2'
$EMACSCLIENT = "emacsclient -a 'emacs-server-start' -nw --socket-name=$TTY"
aliases['emacsclient'] = $EMACSCLIENT
aliases['e'] = $EMACSCLIENT
# aliases['cdpwd'] = 'cd `pwd`'
def free(args, stdin=None):
disk_info = $(diskutil info /)
return [i for i in disk_info.splitlines() if "Free" in i][0] + '\n'
aliases['free'] = free
del free
def sizeup(args, stdin='.'):
du -a -h -x dir | gsort -h
aliases['sizeup'] = sizeup
del sizeup
# TODO: Does this do the right thing if the command fails, and if it is
# backgrounded?
def saydone(args, stdin=None):
@(args)
say "done"
aliases['saydone'] = saydone
del saydone
def cdd(args, stdin=None):
cd @("/Users/aaronmeurer/Documents/" + ''.join(args))
aliases['cdd'] = cdd
del cdd
def cdc(args, stdin=None):
cd @("/Users/aaronmeurer/Documents/Continuum/" + ''.join(args))
aliases['cdc'] = cdc
del cdc
# Typos
aliases['it'] = 'git'
aliases['gi'] = 'git'
aliases['tit'] = 'git'
aliases['bit'] = 'git'
aliases['gt'] = 'git'
aliases['sl'] = 'ls'
# Fun
aliases['👏'] = 'trace'
source-bash ~/Documents/git/contrib/completion/git-completion.bash
source-bash ~/Documents/git/contrib/completion/git-prompt.sh
# Xonsh specific
# Always show a traceback when xonsh errors
$XONSH_SHOW_TRACEBACK=True
# $SHELL_TYPE = 'prompt_toolkit'
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
if !(test -f "/Users/aaronmeurer/miniconda3/bin/conda"):
import sys as _sys
from types import ModuleType as _ModuleType
_mod = _ModuleType("xontrib.conda",
"Autogenerated from $(/Users/aaronmeurer/miniconda3/bin/conda shell.xonsh hook)")
__xonsh__.execer.exec($("/Users/aaronmeurer/miniconda3/bin/conda" "shell.xonsh" "hook"),
glbs=_mod.__dict__,
filename="$(/Users/aaronmeurer/miniconda3/bin/conda shell.xonsh hook)")
_sys.modules["xontrib.conda"] = _mod
del _sys, _mod, _ModuleType
# <<< conda initialize <<<