Commit 64ff8b7c3996

Vincent Demeester <vincent@sbr.pm>
2026-01-08 10:31:35
feat(kitty): Enable terminal instance sharing via remote control
- Allow multiple terminal windows to share the same kitty session - Fix socket path to use hyphen instead of space for compatibility - Handle kitty's automatic PID suffix in socket discovery Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent efaca60
Changed files (3)
dots
.config
home
common
desktop
pkgs
my
scripts
dots/.config/niri/config.kdl
@@ -178,7 +178,7 @@ binds {
 
     // Mod+T hotkey-overlay-title="Open a Terminal: kitty" { spawn "kitty"; }
     Mod+M { spawn "kitten" "quick-access-terminal"; }
-    Mod+Return hotkey-overlay-title="Open a Terminal" { spawn "kitty"; }
+    Mod+Return hotkey-overlay-title="Open a Terminal" { spawn "kitty-launch"; }
     Mod+Shift+Return hotkey-overlay-title="Open Emacs (client)" { spawn "emacsclient" "-c"; }
     Mod+Control+Return hotkey-overlay-title="Open Emacs" { spawn "emacs"; }
     Mod+Control+Alt+Return hotkey-overlay-title="Open Emacs Anywhere" { spawn "emacsclient" "-eval" "(vde/type)"; }
home/common/desktop/kitty.nix
@@ -7,7 +7,7 @@
       close_on_child_death = "yes";
       font_family = "JetBrains Mono";
       tab_bar_edge = "top";
-      listen_on = "unix:/tmp/my kitty";
+      listen_on = "unix:/tmp/my-kitty";
       allow_remote_control = "yes";
       macos_option_as_alt = "yes";
       copy_on_select = "yes";
pkgs/my/scripts/bin/kitty-launch
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+# Launch a new kitty window, either in existing instance or new one
+
+# Use KITTY_LISTEN_ON if available (when launched from within kitty)
+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-)
+    if [ -n "$SOCKET" ]; then
+        exec kitty @ --to "unix:$SOCKET" launch --type=os-window
+    else
+        # No existing instance, start fresh
+        exec kitty
+    fi
+fi