Commit eeca3b3913b5

Vincent Demeester <vincent@sbr.pm>
2026-02-23 14:41:32
fix(kitty): validate socket PID in kitty-launch
Stale sockets from dead kitty processes caused the first Mod+Return to silently fail by connecting to a dead socket. Now checks each socket's PID is alive and cleans up stale ones before falling through to a fresh kitty start.
1 parent 7aa6222
Changed files (1)
pkgs
my
scripts
pkgs/my/scripts/bin/kitty-launch
@@ -5,8 +5,21 @@
 if [ -n "$KITTY_LISTEN_ON" ]; then
     exec kitty @ launch --type=os-window
 else
-    # Find the socket with PID suffix (kitty auto-appends PID)
-    SOCKET=$(find /tmp -maxdepth 1 -name 'my-kitty-*' -type s -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-)
+    # Find a live kitty socket (kitty auto-appends PID to the socket name)
+    # Check each socket's PID is still alive, clean up stale ones
+    SOCKET=""
+    while IFS= read -r line; do
+        sock="${line#* }"
+        pid="${sock##*-}"
+        if kill -0 "$pid" 2>/dev/null; then
+            SOCKET="$sock"
+            break
+        else
+            # Clean up stale socket from dead process
+            rm -f "$sock"
+        fi
+    done < <(find /tmp -maxdepth 1 -name 'my-kitty-*' -type s -printf '%T@ %p\n' 2>/dev/null | sort -rn)
+
     if [ -n "$SOCKET" ]; then
         exec kitty @ --to "unix:$SOCKET" launch --type=os-window
     else