Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tmux create window failed: index in use: 0

Tags:

shell

tmux

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?

like image 507
nwalke Avatar asked Dec 02 '22 19:12

nwalke


2 Answers

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'
like image 149
tonchis Avatar answered Dec 23 '22 09:12

tonchis


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
like image 37
chepner Avatar answered Dec 23 '22 09:12

chepner