Mosh log in automatically reattach tmux session

Lionel picture Lionel · Jun 12, 2012 · Viewed 7.2k times · Source

I'm using Mosh with tmux

I want to run the command "tmux attach -t 0 -d" after mosh connects successfully.

How do I automatically call a command to reattach tmux when I successfully log via mosh?

Answer

chepner picture chepner · Jun 12, 2012

This works:

mosh $REMOTE tmux attach   # I didn't expect this to work

but neither of these do:

mosh $REMOTE "tmux attach -d"  # This should probably work
mosh $REMOTE tmux attach -d    # This correctly interprets -d as a mosh option

UPDATE: As Chris Johnson points out, you can use the '--' argument turn off option processing, so that the entire tmux command is sent to the remote server as a command:

mosh $REMOTE -- tmux attach -t 0 -d