diff options
-rw-r--r-- | python/.config/python/startup.py | 33 | ||||
-rw-r--r-- | sh/.profile | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/python/.config/python/startup.py b/python/.config/python/startup.py new file mode 100644 index 0000000..15fe43c --- /dev/null +++ b/python/.config/python/startup.py @@ -0,0 +1,33 @@ +# Store interactive Python shell history in ~/.cache/python/history +# instead of ~/.python_history. +# +# Create the following .config/python/startup.py file +# and export its path using PYTHONSTARTUP environment variable: +# +# export PYTHONSTARTUP="${XDG_CONFIG_HOME:-$HOME/.config}/python/startup.py" + +import atexit +import os +import readline + +xdg_cache = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache")) +xdg_python_history = os.path.join(xdg_cache, "python", "history") + +histfile = os.getenv("PYTHONHISTFILE", xdg_python_history) +alt_histfile = os.path.expanduser("~/.python_history") + +if not os.path.exists(histfile) and os.path.exists(alt_histfile): + histfile = alt_histfile + +histfile = os.path.abspath(histfile) +cache_directory, _ = os.path.split(histfile) + +os.makedirs(cache_directory, exist_ok=True) + +try: + readline.read_history_file(histfile) + readline.set_history_length(1000) +except FileNotFoundError: + pass + +atexit.register(readline.write_history_file, histfile) diff --git a/sh/.profile b/sh/.profile index 524475d..69bdd9f 100644 --- a/sh/.profile +++ b/sh/.profile @@ -49,6 +49,8 @@ export RUSTUP_HOME="$XDG_DATA_HOME/rustup" export CARGO_HOME="$XDG_DATA_HOME/cargo" export PATH="$PATH:$CARGO_HOME/bin" +export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup.py" + export GOPATH="$XDG_DATA_HOME/go" export PATH="$PATH:$GOPATH/bin" |