From be88417d59883e227b522d56a500d0967c18db3a Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Sun, 23 Aug 2020 11:17:01 +0100 Subject: [PATCH] python: move .python_history to $XDG_CACHE_DIR/python Courtesy of https://codeberg.org/nycex/dotfiles/commit/89fd8cc6482ba671329f39ee196f7bec4381519a Signed-off-by: Joe Groocock --- environment.d/10-profile.conf | 2 +- python/startup | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 python/startup diff --git a/environment.d/10-profile.conf b/environment.d/10-profile.conf index 5651d37..ba1d542 100644 --- a/environment.d/10-profile.conf +++ b/environment.d/10-profile.conf @@ -18,7 +18,7 @@ GNUPGHOME="$XDG_CONFIG_HOME/gnupg" GOPATH="$XDG_DATA_HOME/go" NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/npmrc" #PASSWORD_STORE_DIR="$XDG_DATA_HOME/pass" -PYTHONHISTFILE="$XDG_DATA_HOME/python/histfile" +PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup" RUSTUP_HOME="$XDG_DATA_HOME/rustup" TERMINFO="$XDG_DATA_HOME/terminfo" TERMINFO_DIRS="$XDG_DATA_HOME/terminfo:/usr/share/terminfo" diff --git a/python/startup b/python/startup new file mode 100644 index 0000000..8da7218 --- /dev/null +++ b/python/startup @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +import atexit +import os +import readline + +xdg_cache_home = os.environ['XDG_CACHE_HOME'] + +if xdg_cache_home is None or xdg_cache_home == "": + xdg_cache_home = os.path.join(os.path.expanduser("~"), ".cache") + +python_cache_dir = os.path.join(xdg_cache_home, "python") +if not os.path.isdir(python_cache_dir): + os.mkdir(python_cache_dir) + +histfile = os.path.join(python_cache_dir, "history") + +try: + readline.read_history_file(histfile) + readline.set_history_length(10000) +except FileNotFoundError: + pass + +atexit.register(readline.write_history_file, histfile)