Tmux to create a window if it doesn’t exist yet

tmux

Is it possible to configure tmux so that when you want to switch to a window that doesn't exist, it creates the window and then switches (avoiding Ctrl-b c) ?

Best Answer

Add this to ~/.tmux.conf:

bind-key 0 if-shell 'tmux select-window -t :0' '' 'new-window -t :0'

This will first attempt to switch to window 0, and if that failed, create it.

Repeat for 1-9.

Related Question