shellsshtmuxmosh

How can I run complicated commands on establishing a mosh connection?


With ssh I can do this:

ssh REMOTE -t 'tmux a || tmux'

With mosh the best I can do is this:

mosh REMOTE -- tmux a

But this won't work:

mosh REMOTE -- tmux a || tmux

Neither does this: (It doesn't matter whether it's single quote or double quote, I tried both)

mosh REMOTE -- 'tmux a || tmux'

So, my question is: How am I supposed to do this job?


Solution

  • Well, it seems that I have to explicitly use a shell to execute command:

    mosh REMOTE -- sh -c 'tmux a || tmux'
    

    EDIT

    Instead of doing tmux a || tmux, a better way is add new-session to ~/.tmux.conf and just run tmux. That would make things much easier. I can do things like this now:

    mosh REMOTE -- tmux
    

    Awesome!