Get the wrong tmux session when connecting kakoune to a given session


Let’s say that I start a kakoune session named “k1” in a tmux session named “t1”.

Then I open a new terminal with a new tmux session “t2”, and start a kakoune client connect to “k1” ( kak -c k1)

Now if I want to get the name of the current tmux session from my connected kakoune client ( running %sh{ tmux display-message -p '#S' } ) I don’t get “t2” but “t1” instead.

How can I get the tmux session in which the client is running, instead of the tmux session in which the kakoune session is running?

Since tmux communicates the active session using environment variables, you can re-export the client versions for the command (which runs on the server):

echo %sh{TMUX_SESSION=“$kak_client_env_TMUX_SESSION” tmux display-message -p ‘#S’}


Which tmux version are you running ?
I think TMUX_SESSION doesn’t exist with my version of tmux ( I’m running 2.8 )

I have just used tmux_session=$(echo "$kak_client_env_TMUX" | rev | cut -d',' -f1 | rev) and it work well for me,
Thanks a lot !

I was answering from my iPad and the environment variable name was just wrong. The full command should be like so:

echo %sh{
   TMUX="$kak_client_env_TMUX" \
       TMUX_PANE="$kak_client_env_TMUX_PANE" \
       tmux display-message -p '#S'

While you can get the session from the TMUX variable yourself, I would recommend leaving its contents as a “black box” for tmux to parse, since it is not documented. with the above trick, you can run any tmux command as though it were in the client, not just getting the session. ($TMUX_PANE is not required for the above command, but why not?)

That solution doesn’t work for me, which is sad because it is more elegant than the dirty session parsing, but I guess I’ll stick with that for now :confused: