1

Currently, I have some scripts to open up a new tmux session and populate that session with new windows and panes. This works fine, but sometimes I just want a window or two for monitoring and don't really want to create a whole new session and switch over to it.

My questions is would it be possible to have a script that creates a new window on an existing session?

I have tried a script to create a new window targeting a specific session using something like this :

tmux new-window -t "${current_session}" "${new_window}"

This makes the screen flash on the target session but no window is added. I have tried using the following on the target session with no luck.

:refresh-client

Also tried using send-keys but this seems to send keycodes as plain text (captured with vim on target session):

^B:new-window

UPDATE: Using the first method, during the screen flash of the target session, I can see that the last tmux tab does change to the "${new_window}" label for a fraction of a micro second, but it looks to be in the place of a current tab.

2
  • In your tmux new-window … the operand that is not an option-argument is a shell command. It's "${new_window}" in your case. What is ${new_window} then? If it's not a valid shell command then no wonder the new window exits immediately. Feb 18, 2020 at 17:25
  • Awesome, thanks. I though the last argument passed was the window name! Feb 21, 2020 at 15:09

1 Answer 1

2

Yes, you use new-window:

tmux neww -tmysession: -- emacs

If it makes the client redraw but the window isn't created, probably the command you are running is exiting. Are you sure you have the right command and it is in the PATH the new window will have? Try using sleep 1000 to test, or not giving a command at all so tmux starts a shell.

1
  • 1
    Great, as always I should have read the man pages: new-window [-adkP] [-c start-directory] [-F format] [-n window-name] [-t target-window] [shell-command] I thought the window name was an argument to the command not a flag. Thanks for you response. Feb 21, 2020 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .