Tmux equivalent of “screen -D -R”

gnu-screentmux

I would like to know if there is a way to get tmux to behave like screen -D -R so I could say, have the command as a default command in Putty.

These screen switches would force detach of an existing screen session for my user (even if it was still active and logged-in somewhere else) and reattach it to the current session. Also, in the case that no screen session existed, it would create a new one.

I like tmux and can see clear benefits over screen, but the existence of this feature would really seal the deal.

tmux attach doesn't seem to create a new session if there isn't one.

The man page for tmux says:

If no server is started, attach-session (attach) will attempt to start it;
this will fail unless sessions are created in the configuration
file.

What does the section in bold mean? (I can't find an example of creating a session in the conf file).

Best Answer

Yes:

$ tmux attach -d || tmux new

-d is necessary to behave like screen -D, ie, detach everybody else.

Connect by ssh, then attach or create could be something like:

$ cat bin/stmux
#!/bin/sh
exec ssh -t $@ 'tmux attach -d || tmux new'

$ stmux my.remote.box
Related Question