4

I have enabled tmux plugin in oh-my-zsh with ZSH_TMUX_AUTOSTART=true and now every time I open terminal I am attached to a session. That part is really nice.

The problem is – now I can't start a new session and get access to shell.

Is there a way to start a new session without disabling tmux plugi?

$ tmux new-session -s new
sessions should be nested with care, unset $TMUX to force

I have openend a ticket on github: https://github.com/robbyrussell/oh-my-zsh/issues/3192

2 Answers 2

2

Without -d, new-session will automatically attach to the new session (you probably do not want nested sessions*, thus the warning). What you probably want to do is create a new “detached” session and then switch the current client to that new session. I do not think new-session has an option to handle this use case, but it is fairly easy to do with a bit of shell scripting:

tmux-new() {
  if [[ -n $TMUX ]]; then
    tmux switch-client -t "$(TMUX= tmux -S "${TMUX%,*,*}" new-session -dP "$@")"
  else
    tmux new-session "$@"
  fi
}

# example usage:
tmux-new -s new

If there is no TMUX, then just run tmux new …. Otherwise,

  • unset TMUX to avoid the error while using -S to point to the current server,
  • add -d to create a detached session, and
  • add -P to print out the name of the new session (this requires tmux 1.8 or later).

The output (the new session’s name) is then given to switch-client.

If you do not have tmux 1.8 you might have to rework it a bit (e.g. make the function take a mandatory argument that names the new session so that you can pass it to both new-session and switch-client).

* You would have two status bars; it is complicated to type tmux commands to the inner session; and it may do odd things if you switch the inner client to view the outer session (think: hall of mirrors).
† Maybe the warning should be suppressed when using -d

3
  • Hmm, something doesn't work here. gist.github.com/firedev/204119182d482848bb71
    – firedev
    Oct 7, 2014 at 7:17
  • @Nick: Er, only the first of those gisted commands uses uses the function. It probably needs a -s in there (i.e. tmux-new -s test), otherwise you are just starting (and switching to) a session with a window that runs the command test (which probably just immediately exits with a non-zero result). Oct 7, 2014 at 8:34
  • I just tried to run commands in the terminal. tmux-new -s test doesn't do anything either.
    – firedev
    Oct 9, 2014 at 3:32
1

tmuxinator solved it:

tmuxinator start [project]

And it breaks through the current tmux session straight into the new one.

You must log in to answer this question.

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