-
Notifications
You must be signed in to change notification settings - Fork 2
/
startup.py
61 lines (47 loc) · 1.29 KB
/
startup.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
from pprint import pprint as pp
from pdb import pm
import os
import sys
def has_readline():
try:
import readline
return True
except ImportError:
return False
def setup_history():
"""Setup a persisitent history file."""
import os
import readline
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
def setup_completer():
"""Setup readline completetion."""
import readline
import rlcompleter
readline.parse_and_bind("tab: complete")
def setup_prompt():
import os
import sys
BLUE = "\033[1;34m"
NOCOLOR = "\033[0m"
if os.environ['TERM'] != 'dumb':
sys.ps1 = "%s>>> %s" % (BLUE, NOCOLOR)
if has_readline():
setup_history()
setup_completer()
def hcl():
"""Clear readline history."""
try:
clear = raw_input("Clear history? [y|N]: ")
if clear in ('y', 'Y', 'yes', 'Yes'):
import readline
readline.clear_history()
except EOFError:
pass
setup_prompt()
del(has_readline, setup_history, setup_completer, setup_prompt)