-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpythonrc
61 lines (49 loc) · 1.71 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# $PYTHONSTARTUP - Python interactive startup script
# vim: ft=python:ts=4:sw=4:et
# Import useful stuff for interactive REPLs
import math
import os
import re
import subprocess
import sys
from pprint import pprint
pp = pprint
# Replacement for help(obj)
try:
from rich import inspect
hh = lambda *v, **kv: inspect(*v, methods=True, **kv)
except ImportError:
hh = help
def _init_():
import atexit
import readline
import rlcompleter
if hasattr(sys, "__interactivehook__"):
# As of v3.4, sys.__interactivehook__ in site.py already performs the
# same except with ~/.python_history as the path, and only if history
# is still empty after our read_history_file call.
#
# This means that the 1st startup will create *both* histfiles on exit,
# although the 2nd startup will use ours. Remove the site.py hook to
# avoid this.
del sys.__interactivehook__
hist_file = os.path.expanduser("~/.local/state/python_history")
readline.read_init_file()
readline.parse_and_bind("tab: complete")
if os.path.exists(hist_file):
readline.read_history_file(hist_file)
atexit.register(lambda: readline.write_history_file(hist_file))
rl_hide = lambda s: "\001%s\002" % s
csi = lambda s: rl_hide("\033[%sm" % s)
color = "38;5;169" if sys.version_info[0] >= 3 else "38;5;67"
name = "py%d.%d " % sys.version_info[0:2]
sys.ps1 = csi("") + csi(color) + name + csi("1") + ">>>" + csi("") + " "
sys.ps2 = " " * len(name) + csi(";1;30") + "..." + csi("") + " "
# Pretty-printing for data structures
try:
import rich.pretty
rich.pretty.install()
except ImportError:
pass
_init_()
del _init_