This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdot_pythonrc
55 lines (47 loc) · 1.78 KB
/
dot_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
# Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the Esc key by default (you can change it - see readline docs).
#
# ~/.pythonrc, python startup script
# set the following environment variable to run this file when the
# python interactive interpreter is started:
# export PYTHONSTARTUP=$HOME/.pythonrc
# PYTHONSTARTUP does *not* expand "~", so you have to put the
# full path to your home directory here:
from __future__ import print_function
def activate_readline():
import rlcompleter
import atexit
import os
import sys
import readline
home_path = os.environ['HOME']
# Set up inputrc and tab completion.
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
readline.parse_and_bind('"\C-p": history-search-backward')
readline.parse_and_bind('"\C-n": history-search-forward')
readline.parse_and_bind('set editing-mode emacs')
readline.parse_and_bind('set horizontal-scroll-mode On')
readline.parse_and_bind('set completion-ignore-case on')
# Save history at exit.
history_path = os.path.expanduser(os.path.join(home_path, '.pyhistory'))
def save_history(history_path=history_path):
import readline
readline.write_history_file(history_path)
atexit.register(save_history)
if os.path.exists(history_path):
readline.read_history_file(history_path)
activate_readline()
del activate_readline
# docstring convenience function
def doc(o):
print(o.__doc__)