Can daemon clients use kitty?

When daemonizing a session, clients can’t seem to use kitty at all?

Examples:

setsid kak -s test -d &

  • can join a client, no kitty commands loaded.

/usr/bin/env setsid kak -s test -d &

  • can join a client, kitty commands loaded

In both cases nothing happens when using:
:new, :repl-new, or :nop %sh{kitty @ set-tab-title test}

I briefly tried tmux as well, and had the same experience.

Should this work? Can it work?

It depends how kitty commands (like kitty @ set-tab-title) figure out which kitty process to connect to. I’m not familiar with kitty, but I am familiar with tmux, so I’ll talk about that.

When tmux starts up, it creates a Unix-domain socket in a private location in the filesystem. When tmux launches a shell inside itself, it sets the $TMUX environment variable to point at that socket. Since environment variables are inherited, any process the shell starts can read $TMUX and talk to the the tmux session it’s running inside of (that’s actually how Kakoune detects whether to load the tmux plugin at all). For example, let’s say you’re running Kakoune inside tmux:

tmux
 |
 +- kak

…and inside Kakoune (with the tmux plugin loaded) you run :new. That winds up running tmux new-window kak -c $kak_session so the new Kakoune client connects to the existing session. First Kakoune launches a new tmux process:

tmux
 |
 +- kak
     |
     +- tmux new-window kak -c 1234

The new tmux process checks $TMUX, connects to the session socket, and tells the session to launch a new window and run Kakoune inside it:

tmux
 |
 +- kak
 |
 +- kak -c 1234

However, if the original Kakoune session was started outside tmux, it won’t have the $TMUX environment variable, so there’s no way for :new to figure out what tmux session the new window should be created in.

You might like to think about it this way: imagine you start a Kakoune session as a daemon, then connect to it from a client running inside tmux, and another client running inside Kitty. Then a hook (without user interaction) tries to run :new - how can it know where the new client should be created?

Thanks (again) for dropping some knowledge.
Exactly what I needed to point me in the right direction.

Kitty can communicate over a unix socket like tmux when configured.
And kakoune’s kitty rc’s for windowing and repl were recently updated to support this.

I added this to my kitty.conf:

allow_remote_control yes
listen_on unix:/tmp/mykitty

and all was good. Such a relief.

I was scripting some project setup, trying too many new things at once,
and have been struggling to understand all the pieces.

1 Like