(For context: I have the following slightly unusual use case for tmux because I am using the Overmind process manager, which uses its own tmux server connection internally.)
When I create a new session with the same group-name as a previous session so that the group of windows is shared between these two sessions, I would like to automatically start the new session with its "current window" open to the same "current window" as the first session.
So for example, if I have a session called overmind
with the following windows, and window 2 is the current window:
1 2* 3
When I call :new-session -t overmind
inside this session, I'd like the new session with the same group of 3 windows to start, with window "2" set to the current window:
1 2* 3
When I run :new-session -t overmind
now, however, it starts the new session like so:
1* 2 3
How do I accomplish setting window 2 to be "current window" automatically?
This works for me with tmux 3.3a
:
:run 'sess=`tmux new -d -P -t "#{session_name}"` && tmux switch-cli -t "${sess}#{window_index}" '
You can bind to a key in tmux.conf for convenience like this:
bind z run 'sess=`tmux new -d -P -t "#{session_name}"` && tmux switch-cli -t "${sess}#{window_index}" '