-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpythonrc.py
53 lines (40 loc) · 1.06 KB
/
pythonrc.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
# vim: ft=python
import os
import sys
import atexit
from pprint import pprint as p
imports = ['os', 'sys', 'atexit']
try:
import readline
imports.push('readline')
import rlcompleter
imports.push('rlcompleter')
# Avoid errors about unused imports
assert rlcompleter
assert p
readline.parse_and_bind('tab: complete')
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
except Exception:
print("!!!! Failed to setup readline history")
# Report non-default imports
print("Imported " + ", ".join(imports))
h = [None]
class Prompt:
def __init__(self, prompt='h[%d] >> '):
self.prompt = prompt
def __str__(self):
try:
if _ not in h:
h.append(_)
except NameError:
pass
return self.prompt % len(h)
def __radd__(self, other):
return str(other) + str(self)
sys.ps1 = Prompt()
sys.ps2 = '... '