-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path.pystartup
40 lines (26 loc) · 995 Bytes
/
.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
#!/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:
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 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