-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pythonrc
71 lines (58 loc) · 1.75 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
A custom configuration for interactive Python sessions.
Features:
- Colored PS1 and PS2 prompts.
- Persistent readline history.
- Four spaces instead of tabs.
- Tab completion in any Python.
Docs:
- https://tiswww.case.edu/php/chet/readline/readline.html
- https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP
- https://docs.python.org/3/library/sys.html#sys.ps1
"""
import atexit
import os
import readline
import rlcompleter
import sys
# We need RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE to display correctly.
sys.ps1 = "\001\033[34m\002>>>\001\033[0m\002 " # Blue PS1.
sys.ps2 = "\001\033[35m\002...\001\033[0m\002 " # Magenta PS2.
# Keep 10,000 lines of history at ~/.python_history.
history_length = 10000
history_file = os.path.join(os.environ["HOME"], ".python_history")
# Enable tab completion. This is the default in Python 3.
init_line = "tab: complete"
# Copy the existing readline completer.
_default_completer = readline.get_completer()
def spaces_for_tabs(text, state):
"""Insert four spaces instead of tab. Use ctrl+v, tab for real tab."""
if text:
return _default_completer(text, state)
elif state == 0:
return " "
else:
return 0
try:
# Read the history file. Don't fail if we can't.
readline.read_history_file(history_file)
except IOError:
pass
# Set our readline customizations.
readline.set_history_length(history_length)
readline.set_completer(spaces_for_tabs)
readline.parse_and_bind(init_line)
# Write history when the interpreter exits.
atexit.register(readline.write_history_file, history_file)
# Clean up all our imports and definitions.
del (
atexit,
os,
readline,
rlcompleter,
sys,
history_length,
history_file,
init_line,
spaces_for_tabs,
)