diff options
Diffstat (limited to '')
-rw-r--r-- | hm/soispha/conf/python/default.nix | 2 | ||||
-rw-r--r-- | hm/soispha/conf/python/pythonrc | 11 | ||||
-rw-r--r-- | hm/soispha/conf/python/pythonrc.py | 29 |
3 files changed, 30 insertions, 12 deletions
diff --git a/hm/soispha/conf/python/default.nix b/hm/soispha/conf/python/default.nix index 74a2e4c0..826d466d 100644 --- a/hm/soispha/conf/python/default.nix +++ b/hm/soispha/conf/python/default.nix @@ -1,5 +1,5 @@ {config, ...}: { - xdg.configFile."python/pythonrc".source = ./pythonrc; + xdg.configFile."python/pythonrc".source = ./pythonrc.py; programs.zsh.sessionVariables = { "PYTHONSTARTUP" = "${config.xdg.configHome}/python/pythonrc"; }; diff --git a/hm/soispha/conf/python/pythonrc b/hm/soispha/conf/python/pythonrc deleted file mode 100644 index 9173e131..00000000 --- a/hm/soispha/conf/python/pythonrc +++ /dev/null @@ -1,11 +0,0 @@ -import os -import atexit -import readline - -history = os.path.join(os.environ['XDG_DATA_HOME'], 'python/history.py') -readline.read_history_file(history) - -def write_history(): - readline.write_history_file(history) - -atexit.register(write_history) diff --git a/hm/soispha/conf/python/pythonrc.py b/hm/soispha/conf/python/pythonrc.py new file mode 100644 index 00000000..5c2ed3b9 --- /dev/null +++ b/hm/soispha/conf/python/pythonrc.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + + +def is_vanilla() -> bool: + import sys + + return not hasattr(__builtins__, "__IPYTHON__") and "bpython" not in sys.argv[0] + + +def setup_history(): + import os + import atexit + import readline + from pathlib import Path + + if state_home := os.environ.get("XDG_DATA_HOME"): + state_home = Path(state_home) + else: + state_home = Path.home() / ".local" / "state" + + history: Path = state_home / "python" / "history" + + readline.read_history_file(str(history)) + atexit.register(readline.write_history_file, str(history)) + + +if is_vanilla(): + setup_history() +# vim: ft=python |