2

I've been using tmux launched by default as part of my shell at all times for some time now and find it very convenient. At the same time ssh'ing from inside tmux to another system is not ideal because I end up with nested multiplexers. My solution has been to use different terminals — or rather the same terminal launched with different parameters so it doesn't start up up tmux and prompts me for a machine to ssh to instead.

This works, but it means that each terminal window is only good for the machine I launched it for. Detatching from tmux drops the terminal since it was exec'ed; likewise logout of the remote ssh session and the terminal drops.

Switching between tmux sessions is easy, I can change what session tmux is attached to from inside tmux. What I would like to do is have an option from inside tmux to ssh to another machine in a way that swaps out the main process in the shell from tmux to the ssh session. I could imagine two ways this might work:

  1. Swapping out the exec'ed process somehow.
  2. Enabling some sort of tmux feature that backgrounded the usual muli-pane interface and foregrounded another process passing all input/output through to it until it dies, then returning to the tmux session.

However I don't know if either is actually achievable. Or perhaps there is another way? How could this workflow be achieved?

  • Probably not (to the question). I use an alias v for running screen to avoid this problem. – Thomas Dickey Feb 3 '16 at 10:03
  • @ThomasDickey Been there done that. But even one letter plus enter means sometimes I was too lazy to jump in a session for just that one quick thing until after I realized it wasn't going to be as quick as I thought it was. Also a number of key bindings that effect the shell itself and the way I manage copy/paste now kind of depends on everything being in tmux, so the extra step is a waste. – Caleb Feb 3 '16 at 10:05
  • Why are you ruling out keeping an intermediate process between the terminal emulator and (tmux or ssh)? – Gilles Feb 3 '16 at 21:46
  • @Gilles I'm not necessarily. It did seem like there would already be some mechanism to handle this kind of process swapping. If there really isn't then the question becomes what sort of switcher can I put in there that won't get in the way of either mosh or tmux doing their jobs but allows me to drop out of either and switch to the other. – Caleb Feb 3 '16 at 22:39
  • What I do to avoid hassles with nested tmux: On the remote system, instead of calling tmux directly, call a Shell-Script, that checks the $TERM-Variable. There you can see, if the ssh-session was launched from a tmux. In that case, just use a different escape-Character, and set a different Status-Bar color. e.g. "Green StatusBar with ^A for Outer Tmux, Blue Statusbar with ^B for nested Session(s)" – Alex Stragies Jun 29 '16 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.