15

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?

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
Lionel
  • 3,188
  • 5
  • 27
  • 40

1 Answers1

24

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
chepner
  • 497,756
  • 71
  • 530
  • 681
  • 2
    I am not a *mosh* user, but the [*mosh* web page](http://mosh.mit.edu/#usage) indicates that the appropriate syntax might be `mosh $REMOTE -- attach -d` (or `mosh -- $REMOTE attach -d`). *mosh* is a Perl program that uses [GetOpt::Long](http://perldoc.perl.org/Getopt/Long.html). Its documentation describes [how `--` works](http://perldoc.perl.org/Getopt/Long.html#Mixing-command-line-option-with-other-arguments). Any *mosh* options must come before the `--`. – Chris Johnsen Jun 13 '12 at 03:54
  • 1
    Another example using non-default ssh port: `mosh --ssh="ssh -p 822" ed8@vm-ed -- tmux attach -t irc`. The hostname is `vm-ed` – Édouard Lopez Jun 25 '14 at 10:21