Reputation: 3209
I have a script like so that I'd like to create a tmux session with windows with various server connections:
tmux new-session -d -s server-connections
tmux new-window -t server-connections:0 -n 't-u14-nickpl' 'ssh T-U14-NickPL'
tmux new-window -t server-connections:1 -n 't-u12-dev1' 'ssh T-U12-Dev1'
tmux attach -t server-connections
When I run that file, I get create window failed: index in use: 0
. At first I thought maybe the script was executing so quickly it attached to the window at index 0 faster than the command could be run, so I introduced a sleep just to be sure.
tmux new-session -d -s server-connections
tmux new-window -t server-connections:0 -n 't-u14-nickpl' 'ssh T-U14-NickPL'
tmux new-window -t server-connections:1 -n 't-u12-dev1' 'ssh T-U12-Dev1'
sleep 4
tmux attach -t server-connections
But still I get create window failed: index in use: 0
and then the sleep would happen.
What do I need to change to bind to that window at index 0?
Upvotes: 8
Views: 3830
Reputation: 638
chepner's answer is correct, but you can also avoid specifying window numbers by appending windows with the -a
option:
tmux new-window -a -t server-connections -n 't-u14-nickpl' 'ssh T-U14-NickPL'
tmux new-window -a -t server-connections -n 't-u12-dev1' 'ssh T-U12-Dev1'
Upvotes: 19
Reputation: 530882
A new session always has an initial window, so window index 0 is already taken as soon as new-session
completes. Instead of an explicit new-window
command, just specify the information with the new-session
command itself.
tmux new-session -d -s server-connections -n 't-u14-nickpl' 'ssh T-U14-NickPL'
tmux new-window -t server-connections:1 -n 't-u12-dev1' 'ssh T-U12-Dev1'
tmux attach -t server-connections
Upvotes: 5