-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpystartup
54 lines (39 loc) · 1.1 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
import os
import sys
import atexit
import rlcompleter
import readline
HISTORY_FILE_PATH = os.path.expanduser("~/.python_history")
class IndentableCompleter(rlcompleter.Completer):
def complete(self, text, state):
if text == "" or text.isspace():
return [" ", None][state]
else:
return super().complete(text, state)
def save_history(history_file_path=HISTORY_FILE_PATH):
import sys
if sys.version_info.major > 2 and sys.version_info.minor < 13:
import readline
readline.write_history_file(history_file_path)
def load_history(history_file_path=HISTORY_FILE_PATH):
if (
sys.version_info.major > 2
and sys.version_info.minor < 13
and os.path.exists(history_file_path)
):
readline.read_history_file(history_file_path)
load_history()
readline.parse_and_bind("tab: complete")
readline.set_completer(IndentableCompleter().complete)
atexit.register(save_history)
del (
os,
atexit,
readline,
rlcompleter,
sys,
save_history,
load_history,
HISTORY_FILE_PATH,
)