I am trying to make new session with the same name a as the current one with an extra -2 on the end of the name.

bind C new-session -c "#{pane_current_path}" -s "#{session_name}"-2

The session_named does not interpolate the variable name it takes that texts literally, creating a session with the name "#{session_name}"-2

I am also running tmux 2.6


This works for me in tmux 2.1 and 2.6. You need to detach the new session.

bind-key C run-shell 'tmux new-session -d -c "#{pane_current_path}" -s "#{session_name}-2"'

If you want to switch to the new session, you can use switch-client to move to this client to the "next" session.

bind-key C run-shell \
 'tmux new-session -d -c "#{pane_current_path}" -s "#{session_name}-2"' \;\
  switch-client -n

Note the backslash before ; and also the ones used here to split the binding over 3 lines for legibility.

  • I get an error saying 'tmux new-session -d -c "/Users/Dylan" -s "session-2"' returned 1 – Dylanthepiguy Mar 1 '18 at 18:37
  • You'll get that if you already have a session named session-2. I just tried on tmux 2.6 and it was ok for me otherwise. Sorry, I don't know what else to suggest. – meuh Mar 1 '18 at 19:22
  • Ah, it does create the session, ocassionaly. Mostly it returns 1 - even if there is no sesion existing yet under the name "#{session_name}-2" – Dylanthepiguy Mar 1 '18 at 20:51
  • You might get some more information on the failure by using tmux -v. This prints debug into 2 files tmux-* in the current directory, but the info isnt easy to understand. – meuh Mar 1 '18 at 20:55
  • Ok, it seems to work. Can the command be modified to switch to the new session when it is created? – Dylanthepiguy Mar 2 '18 at 7:20

First off, when I tried this, I received a warning message about nesting tmux sessions, and tmux refused to perform the operation unless I first unset variable $TMUX, which I wasn't willing to do. So, I'm a bit curious why your binding works at all.

Being that you say that it does work, only that it creates a session with the incorrect name, maybe try this:

bind C new-session -c "#{pane_current_path}" -s "$(tmux display-message -p "#S")-2"

This attempt at a solution uses the shell's command substitution idiom $(..).

  • This creates a session named "$(tmux display-message -p . Even changing "#S" to '#S' just makes a session called $(tmux display-message -p '#S')-2 – Dylanthepiguy Mar 1 '18 at 8:48
  • Never mind, then. Sorry for the trouble, but I had the idiom working on a similar command, create-window, so I thought it would work also for this. – user1404316 Mar 1 '18 at 12:53
  • It might be interesting seeing your working command for create-window – Dylanthepiguy Mar 2 '18 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.