-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpystartup
37 lines (27 loc) · 1.3 KB
/
pystartup
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
# 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).
#
# Store the file in ~/.pystartup, and set an environment variable to point
# to it: "export PYTHONSTARTUP=~/.pystartup" in bash.
import atexit
import os
import readline
import rlcompleter
# This binds the Tab key to the completion function, so hitting the Tab key
# twice suggests completions; it looks at Python statement names, the current
# local variables, and the available module names. For dotted expressions such
# as string.a, it will evaluate the expression up to the final '.' and then
# suggest completions from the attributes of the resulting object. Note that
# this may execute application-defined code if an object with a __getattr__()
# method is part of the expression.
readline.parse_and_bind('tab: complete')
HISTORY_PATH = os.path.expanduser("~/.pyhistory")
def save_history(history_path=HISTORY_PATH):
import readline
readline.write_history_file(history_path)
if os.path.exists(HISTORY_PATH):
readline.read_history_file(HISTORY_PATH)
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, HISTORY_PATH
# vim:ft=python:sw=4:ts=4:et: