From 79cd46b7829d39b225281dfdc14ea9d4b8df91ea Mon Sep 17 00:00:00 2001 From: urosm Date: Sat, 12 Aug 2023 01:29:05 +0200 Subject: [PATCH] add `python` config --- .config/python/pythonrc.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .config/python/pythonrc.py diff --git a/.config/python/pythonrc.py b/.config/python/pythonrc.py new file mode 100644 index 0000000..65ab4ea --- /dev/null +++ b/.config/python/pythonrc.py @@ -0,0 +1,25 @@ +import os +import atexit +import readline + +if "PYTHONHISTFILE" in os.environ: + histfile = os.path.expanduser(os.environ["PYTHONHISTFILE"]) +elif "XDG_STATE_HOME" in os.environ: + histfile = os.path.join(os.path.expanduser( + os.environ["XDG_STATE_HOME"]), "python", "python_history") +else: + histfile = os.path.join(os.path.expanduser("~"), ".python_history") + + +histfile = os.path.abspath(histfile) +_dir, _ = os.path.split(histfile) +os.makedirs(_dir, exist_ok=True) + + +try: + readline.read_history_file(histfile) +except FileNotFoundError: + pass + + +atexit.register(readline.write_history_file, histfile)