forked from acornejo/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonrc
More file actions
57 lines (44 loc) · 1.43 KB
/
pythonrc
File metadata and controls
57 lines (44 loc) · 1.43 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
# 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)
setup_prompt()
setup_history()
setup_completion()
# cleanup symbols
del setup_prompt, setup_history, setup_completion
# import things we want in the global scope of our shell
import os
import re
import sys
from math import *