-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pythonrc
53 lines (44 loc) · 1.08 KB
/
.pythonrc
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
#
# Adapted from http://norvig.com/python-iaq.html
#
import sys
import os
import atexit
# {{{ Readline settings
try:
import readline
import rlcompleter
except ImportError:
print("readline not available")
else:
readline.parse_and_bind('tab: complete')
# Store history between sessions
histfile = os.path.join(os.environ['HOME'], '.python_history')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
# }}}
# {{{ Result history and prompt
h = [None]
class Prompt:
def __init__(self, str='h[%d] >>> '):
self.str = str
def __str__(self):
try:
if _ not in [h[-1], None, h]: h.append(_);
except NameError:
pass
return self.str % len(h)
def __radd__(self, other):
return str(other) + str(self)
if os.environ.get('TERM') in ['xterm', 'vt100', 'screen', 'rxvt-unicode']:
sys.ps1 = Prompt('\001\033[0;33m\002h[%d] >>> \001\033[0m\002')
else:
sys.ps1 = Prompt()
sys.ps2 = ''
# }}}
# {{{ Cleanup
del os
# }}}