-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpythonrc
More file actions
70 lines (56 loc) · 1.84 KB
/
pythonrc
File metadata and controls
70 lines (56 loc) · 1.84 KB
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
# Save as ~/.pythonrc and add 'export PYTHONSTARTUP=~/.pythonrc' to ~/.bashrc
def setup_history():
import os
import atexit
import readline
historyPath = os.path.expanduser("~/.python_history")
if not os.path.exists(historyPath) and not os.path.isdir(historyPath):
try:
open(historyPath, 'w').close()
except IOError:
pass
if os.access(historyPath, os.W_OK):
atexit.register(readline.write_history_file, historyPath)
if os.access(historyPath, os.R_OK):
readline.read_history_file(historyPath)
def setup_prompt():
import sys
import os
if os.environ.get("TERM", "").count("256") > 0:
sys.ps1 = '\001\033[1;36m\002>>> \001\033[0m\002'
sys.ps2 = '\001\033[1;31m\002... \001\033[0m\002'
def setup_completion():
import readline
import rlcompleter
old_complete = readline.get_completer()
def complete(text, state):
if not text:
return ('\t', None)[state]
return old_complete(text, state)
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind '\t' rl_complete")
else:
readline.parse_and_bind("tab: complete")
readline.set_completer(complete)
def setup_local():
import os
import sys
import glob
pythonPath = os.path.join(os.path.expanduser("~"), ".python")
sys.path.insert(0, pythonPath)
for f in glob.glob(os.path.join(pythonPath, "*.py")):
modulename = os.path.basename(f[:-3])
module = __import__(modulename, globals(), locals(), ['*'])
for k in dir(module):
globals()[k] = module.__dict__[k]
setup_prompt()
setup_history()
setup_completion()
setup_local()
# cleanup symbols
del setup_prompt, setup_history, setup_completion, setup_local
# import things we want in the global scope of our shell
import os
import re
import sys
from math import *