From 53d847d783585401b4c197a4d8d8ec42da9b34f0 Mon Sep 17 00:00:00 2001 From: Joel Beckmeyer Date: Fri, 12 Apr 2024 21:44:22 -0400 Subject: [PATCH] python: enforce XDG for python_history --- dot_config/environment | 2 ++ dot_config/python/pythonrc | 45 +++++++++++++++++++++++++++ dot_config/xsettingsd/xsettingsd.conf | 5 +-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 dot_config/python/pythonrc diff --git a/dot_config/environment b/dot_config/environment index 0b8d296..f7a615a 100644 --- a/dot_config/environment +++ b/dot_config/environment @@ -31,6 +31,8 @@ export NODE_REPL_HISTORY="$XDG_DATA_HOME"/node_repl_history export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME"/npm/npmrc export PASSWORD_STORE_DIR="$XDG_DATA_HOME"/pass export PATH="$HOME/.local/bin:$PATH:$XDG_DATA_HOME/xxtools:$XDG_DATA_HOME/flutter/bin" +export PYTHONSTARTUP="$XDG_CONFIG_HOME"/python/pythonrc +export PYTHON_HISTORY="$XDG_STATE_HOME"/python_history export RUSTUP_HOME="$XDG_DATA_HOME"/rustup export SQLITE_HISTORY="$XDG_CACHE_HOME"/sqlite_history export WINEPREFIX="$XDG_DATA_HOME"/wine diff --git a/dot_config/python/pythonrc b/dot_config/python/pythonrc new file mode 100644 index 0000000..486f2d6 --- /dev/null +++ b/dot_config/python/pythonrc @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# This entire thing is unnecessary post v3.13.0a3 +# https://github.com/python/cpython/issues/73965 + + +def is_vanilla() -> bool: + """:return: whether running "vanilla" Python""" + import sys + + return not hasattr(__builtins__, "__IPYTHON__") and "bpython" not in sys.argv[0] + + +def setup_history(): + """read and write history from state file""" + import os + import atexit + import readline + from pathlib import Path + + # https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables + if state_home := os.environ.get("XDG_STATE_HOME"): + state_home = Path(state_home) + else: + state_home = Path.home() / ".local" / "state" + if not state_home.is_dir(): + print("Error: XDG_SATE_HOME does not exist at", state_home) + + history: Path = state_home / "python_history" + + # https://github.com/python/cpython/issues/105694 + if not history.is_file(): + with open(history, "w") as f: + f.write( + "_HiStOrY_V2_" + + "\ +\ + " + ) # breaks on macos + python3 without this. + + readline.read_history_file(history) + atexit.register(readline.write_history_file, history) + + +if is_vanilla(): + setup_history() diff --git a/dot_config/xsettingsd/xsettingsd.conf b/dot_config/xsettingsd/xsettingsd.conf index 3949aa0..99516d8 100644 --- a/dot_config/xsettingsd/xsettingsd.conf +++ b/dot_config/xsettingsd/xsettingsd.conf @@ -1,7 +1,7 @@ Gdk/UnscaledDPI 98304 Gdk/WindowScalingFactor 1 Gtk/ButtonImages 1 -Gtk/CursorThemeName "PearDarkCursors" +Gtk/CursorThemeName "breeze_cursors" Gtk/CursorThemeSize 24 Gtk/DecorationLayout "icon:minimize,maximize,close" Gtk/EnableAnimations 1 @@ -9,5 +9,6 @@ Gtk/FontName "Noto Sans, 10" Gtk/MenuImages 1 Gtk/PrimaryButtonWarpsSlider 0 Gtk/ToolbarStyle 3 -Net/IconThemeName "Gruvbox" +Net/IconThemeName "breeze-dark" Net/ThemeName "Breeze" +