-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.py
24 lines (20 loc) · 1.01 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from importlib.util import find_spec
from os import getenv, makedirs
from os.path import exists, join, dirname
import sys
# embed ptpython if it is installed and isn't the current REPL
if "ptpython" not in getenv("_", "") and find_spec("ptpython"):
from ptpython.repl import embed, run_config
from appdirs import user_config_dir, user_data_dir
config_file = join(getenv("PTPYTHON_CONFIG_HOME", user_config_dir("ptpython", "prompt_toolkit")), "config.py")
history_file = join(user_data_dir("ptpython", "prompt_toolkit"), "history")
# create histfile if it doesn't exist (else ptpython complains)
if not exists(history_file):
makedirs(dirname(history_file), exist_ok=True)
with open(history_file, 'w'): pass
sys.exit(embed(globals(), locals(), lambda repl: run_config(repl, config_file), False, history_file))
# if not customize standard python REPL
else:
# make primary prompt shorter because ~/.config/readline/inputrc shows vi editing mode
sys.ps1 = "> "
sys.ps2 = "» "