author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Fri, 14 Oct 2011 15:24:08 +0300 | |
changeset 226 | 97139da73273 |
child 227 | d2bb2c3da51b |
permissions | -rwxr-xr-x |
226
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
1 |
# -*- mode: python -*- |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
2 |
# Add auto-completion and a stored history file of commands to your Python |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
3 |
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
4 |
# bound to the Esc key by default (you can change it - see readline docs). |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
5 |
# |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
6 |
# Store the file in ~/.pystartup, and set an environment variable to point |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
# to it: "export PYTHONSTARTUP=~/.pystartup" in bash. |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
8 |
|
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
9 |
import atexit |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
10 |
import os |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
11 |
import readline |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
12 |
import rlcompleter |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
13 |
|
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
14 |
historyPath = os.path.expanduser("~/.pyhistory") |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
15 |
|
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
16 |
def save_history(historyPath=historyPath): |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
17 |
import readline |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
18 |
readline.write_history_file(historyPath) |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
19 |
|
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
20 |
if os.path.exists(historyPath): |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
21 |
readline.read_history_file(historyPath) |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
22 |
|
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
23 |
atexit.register(save_history) |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
24 |
del os, atexit, readline, rlcompleter, save_history, historyPath |
97139da73273
Enable python statement readline completion and readline history for interactive Python .
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
25 |