From e44d7d3afe55e2275cdf0bd7b8a3ac95baecd17b Mon Sep 17 00:00:00 2001
From: Luca Bilke <bilke@tralios.de>
Date: Fri, 26 Jan 2024 12:43:46 +0100
Subject: [PATCH] compat with reworked remaps script, add pythonrc

---
 bootstrap.sh              |  6 +++---
 files/etc/python/pythonrc | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)
 create mode 100644 files/etc/python/pythonrc

diff --git a/bootstrap.sh b/bootstrap.sh
index a4495a2..5128cdd 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -183,9 +183,9 @@ install_dotfiles() {
 }
 
 select_keymap() {
-	[ -L "${user_home}/.local/share/xkb/compiled/default" ] && return
-	map="$(find "${user_home}/.local/share/xkb/compiled" -type f -printf "%f\n" | fzf --header="Select a default keymap:")"
-	ln -s "$map" "${user_home}/.local/share/xkb/compiled/default"
+	[ -L "${user_home}/.local/share/xkb/compiled/keymap" ] && return
+	map="$(find "${user_home}/.local/share/xkb/compiled" -type f -printf "%f\n" | fzf --header="Select a keymap keymap:")"
+	ln -s "$map" "${user_home}/.local/share/xkb/compiled/keymap"
 }
 
 enable_services() {
diff --git a/files/etc/python/pythonrc b/files/etc/python/pythonrc
new file mode 100644
index 0000000..32a91eb
--- /dev/null
+++ b/files/etc/python/pythonrc
@@ -0,0 +1,32 @@
+# vim: ft=python
+import os
+import atexit
+import readline
+from pathlib import Path
+
+if readline.get_current_history_length() == 0:
+
+    state_home = os.environ.get("XDG_STATE_HOME")
+    if state_home is None:
+        state_home = Path.home() / ".local" / "state"
+    else:
+        state_home = Path(state_home)
+
+    history_path = state_home / "python_history"
+    if history_path.is_dir():
+        raise OSError(f"'{history_path}' cannot be a directory")
+
+    history = str(history_path)
+
+    try:
+        readline.read_history_file(history)
+    except OSError: # Non existent
+        pass
+
+    def write_history():
+        try:
+            readline.write_history_file(history)
+        except OSError:
+            pass
+
+    atexit.register(write_history)