88

Is there a way to use mosh without giving up the local scrollback?

Basically, in some circumstances, IP-roaming is indeed useful and needed, but the extra terminal emulation and key prediction seems to only be getting rid of the local scrollback buffer lines and the session history.

cnst
  • 3,283

4 Answers4

55

Filippo Valsorda has a solution for OS X that incorporates iTerm 2, tmux, and mosh.

His solution uses a single window/tab to connect to a remote shell. The shell survives disconnects (e.g., connection failure, IP changes, laptop reboots) and supports scrollback with a touchpad, copy-paste, and colors.

Caveats are that you must build mosh from source, scrolling is less fluid than native, and click-drag is relayed, so you must hold Option to select.

  • iTerm

    In the Terminal Profile settings, Enable xterm mouse reporting and set Report Terminal Type to xterm-256color.

  • tmux

    Set ~/.tmux.conf on the server to the following. With these settings, if you try to attach and there are no sessions, a new one is created. The settings also enable mouse interactions (and thus touchpad scrolling).

    new-session
    set-window-option -g mode-mouse on
    set -g history-limit 30000
    

    Note: On more recent tmux (i.e. > 2.1), as reported by tmux -V, the various mouse options (mouse-resize-pane, mouse-mode, etc.) have been rewritten to a single option mouse, so you have to change the second line above to set-window-option -gmouseon instead.

    This mouse scroll will also work when you are in keyboard scroll mode (e.g. Ctrl-b then [), described in the article How to scroll in tmux.

  • mosh

    The stable build of mosh is old and does not support mouse reporting (and touchpad scrolling). To install the latest version, do the following:

    OS X (your client)

    brew install --HEAD mobile-shell
    

    Linux/UNIX (the server)

    git clone https://github.com/keithw/mosh.git
    cd mosh/
    sudo apt-get build-dep mosh
    ./autogen.sh && ./configure && make
    sudo make install
    

Now, to connect, just type the following:

mosh HOST -- tmux a
Phil Hord
  • 233
rbrewer
  • 661
21

The terminal emulation is baked pretty deep into the design of mosh, so, no. Mosh works by having both client and server each maintain its local idea of what the screen currently "looks like", and that requires that the server does terminal emulation. This is how the client is able to refresh the contents of the screen after it has been away for a while and lost some data.

I think that an application with the IP roaming feature of mosh but without terminal emulation would end up being quite a different (but simpler) application. For such an application, loss of data (including when the client is off-net for some time) would result in loss or corruption of screen contents. This is an acceptable limitation if the user is using an application where this doesn't matter much (e.g. shell) or an application which has a repaint feature (e.g. vi using Control-L).

The implementors of Mosh are planning scrollback support in the application though, to make up for the fact that your local terminal cannot do it anymore. I guess this would have to work a little bit like screen's scrollback buffer though: controlled by keystrokes, not scrollbar and mouse.

Celada
  • 44,132
10

Eternal Terminal ( https://mistertea.github.io/EternalTerminal/ ) is an alternative to Mosh that supports native scrollback and still allows IP roaming. ET doesn't do the typing prediction, so it may not be suitable if you have a high latency connection (if you are ssh-ing into a drone or from a cell phone), but personally ET does everything I want and supports scrollback.

2

Unchecking "Scroll alternate screen" in Terminal->Preferences->Profiles->Keyboard fixed it for me.

pikachu
  • 137
  • 4
    this answer makes no sense, where do you even get such a menu? – cnst Aug 24 '15 at 20:30
  • 4
    That prefs setting exists, but unchecking it caused scrolling to work only in my local window, ie scrolling down brought into view the lines that were there before i used the mosh command. it did not show me anything which had scrolled off the top of the remote session. – mARK Sep 09 '15 at 01:24
  • 3
    Tried this, but it does not allow you to scroll in the mosh session – magodiez Feb 24 '16 at 17:13