-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpythonrc
43 lines (34 loc) · 1.04 KB
/
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
import atexit
import os
import readline
import time
from libqtile.command.client import InteractiveCommandClient
# enable syntax completion
readline.parse_and_bind("tab: complete")
# clear screen
def clear():
os.system('clear')
c = InteractiveCommandClient()
if 'PYTHONHISTFILE' in os.environ:
history = os.path.expanduser(os.environ['PYTHONHISTFILE'])
elif 'XDG_DATA_HOME' in os.environ:
history = os.path.join(os.path.expanduser(os.environ['XDG_DATA_HOME']),
'python', 'python_history')
else:
history = os.path.join(os.path.expanduser('~'),
'.python_history')
history = os.path.abspath(history)
_dir, _ = os.path.split(history)
os.makedirs(_dir, exist_ok=True)
try:
readline.read_history_file(history)
except OSError:
pass
if readline.get_current_history_length() == 0:
readline.add_history(f'# History created at {time.asctime()}')
def write_history():
try:
readline.write_history_file(history)
except OSError:
pass
atexit.register(write_history)