From ba819b7c24b800d59d31fa72dee8e08b0926a5c6 Mon Sep 17 00:00:00 2001 From: rydesun Date: Sun, 1 Mar 2020 15:17:52 +0800 Subject: [PATCH] Add python repl config remove .python_history --- .config/python/repl_startup.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .config/python/repl_startup.py diff --git a/.config/python/repl_startup.py b/.config/python/repl_startup.py new file mode 100644 index 0000000..cca8cc0 --- /dev/null +++ b/.config/python/repl_startup.py @@ -0,0 +1,19 @@ +import atexit +import os +import readline + + +xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.data')) +data_dir = os.path.join(xdg_data_home, 'python') +readline_history_file = os.path.join(data_dir, 'history') + +try: + readline.read_history_file(readline_history_file) +except FileNotFoundError: + os.makedirs(data_dir, exist_ok=True) + open(readline_history_file, 'wb').close() + readline.read_history_file(readline_history_file) + +readline.set_history_length(1000000) + +atexit.register(readline.write_history_file, readline_history_file)