Commit eeca3b3913b5
Changed files (1)
pkgs
my
scripts
bin
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