diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-05-09 14:17:59 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-05-09 20:33:34 +0200 |
commit | d2b0cee9fa07f41aee79d4018417baa738d7992b (patch) | |
tree | fe393bd081a9c172d0076367b816929b8a3d60da /hm/soispha/conf/python/pythonrc.py | |
parent | fix(hm/conf/nvim/plgs/lsp/servers/ltex): Don't use in html files (diff) | |
download | nixos-config-d2b0cee9fa07f41aee79d4018417baa738d7992b.zip |
fix(hm/conf/python): Correctly tell python to use a history file
Diffstat (limited to '')
-rw-r--r-- | hm/soispha/conf/python/pythonrc.py | 29 |
1 files changed, 29 insertions, 0 deletions
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 |