mywindow="test" tmux -q has-session -t mysession || tmux new -s mysession -d if tmux -q select-window -t mysession:$mywindow then tmux -q attach -t mysession else tmux -q new-window -t mysession -n $mywindow tmux -q send-keys -t mysession:$mywindow "mycommand" ENTER fi