From be2013e4d494ba2c2a87150fd1efa41d8fcd4f76 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Wed, 2 Aug 2023 01:45:32 +0200 Subject: [PATCH] Set XDG vars for python --- home/.cache/python_history | 0 home/.config/python/pythonrc.py | 18 ++++++++++++++++++ home/.config/shell/environment | 3 +++ home/.python_history | 1 - install_user.sh | 3 +-- 5 files changed, 22 insertions(+), 3 deletions(-) delete mode 100644 home/.cache/python_history create mode 100644 home/.config/python/pythonrc.py delete mode 120000 home/.python_history diff --git a/home/.cache/python_history b/home/.cache/python_history deleted file mode 100644 index e69de29..0000000 diff --git a/home/.config/python/pythonrc.py b/home/.config/python/pythonrc.py new file mode 100644 index 0000000..a13196b --- /dev/null +++ b/home/.config/python/pythonrc.py @@ -0,0 +1,18 @@ +import atexit +import os +import readline +from pathlib import Path + +cache_xdg_dir = Path(os.environ.get("XDG_CACHE_HOME", str(Path("~/.cache")))) +cache_xdg_dir.mkdir(exist_ok=True, parents=True) + +history_file = cache_xdg_dir.joinpath("python_history") + +readline.read_history_file(history_file) + + +def write_history() -> None: + readline.write_history_file(history_file) + + +atexit.register(write_history) diff --git a/home/.config/shell/environment b/home/.config/shell/environment index 0ebeb88..ede1c84 100755 --- a/home/.config/shell/environment +++ b/home/.config/shell/environment @@ -44,6 +44,9 @@ export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/npmrc" export NUGET_PACKAGES="$XDG_CACHE_HOME/NuGetPackages" export PARALLEL_HOME="$XDG_CONFIG_HOME/parallel" export RANDFILE="$XDG_CACHE_HOME/rnd" +export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/pythonrc.py" +export PYTHONPYCACHEPREFIX="$XDG_CACHE_HOME/python" +export PYTHONUSERBASE="$XDG_DATA_HOME/python" # Less commonly used applications export _ZL_DATA="$XDG_DATA_HOME/zlua" export SQLITE_HISTORY="$XDG_DATA_HOME/sqlite_history" diff --git a/home/.python_history b/home/.python_history deleted file mode 120000 index e43cfa6..0000000 --- a/home/.python_history +++ /dev/null @@ -1 +0,0 @@ -.cache/python_history \ No newline at end of file diff --git a/install_user.sh b/install_user.sh index 890e241..70e1b31 100755 --- a/install_user.sh +++ b/install_user.sh @@ -62,8 +62,7 @@ pyenv install -l | cut -d' ' -f3 | grep -E '^3\.6\.[0-9]+$' | tail -n 1 | xargs # Copy other user configurations mkdir -p ~/.local cp -ra home/.local/bin ~/.local -cp -a home/.python_history ~ -touch ~/.cache/python_history +cp -ra home/.config/python ~/.config install -m 700 -d ~/.local/share/gnupg mkdir -p ~/.local/share/npm/lib cp -ra home/.config/btop ~/.config