Trying Tmux

Linux

I'll tell you the truth, I don't change my ways just for no reason. I'm definitively not a neophile.

I'm using screen for more than a decade, and if I were to change into tmux, I'd need a good reason, not people telling me it's "modern", nor that it has "plenty of new features", or anything like that.

Well, yesterday I got a real reason. I just learned how to configure it so the screen rolls as well as a native terminal (my worst problem with screen), and so that copy and paste is easier to do than even on the native terminal. Turns-out I can configure it for a better experience than the terminal itself!

So... if it's better than the terminal, why don't I don't simply have it always on? This way I'll never ssh into a machine again, run something, and only after it realize I should have started screen. I'll also have seamless windows for any background thing I may want running. And, let's get honest here, those bars stacking-up on the bottom of the screen as I ssh from a place to another are much fun. AFAIK, I have no use for them, but I want them now.

So, let's get to it.

The How

  • First idea was the obvious one: replacing my default shell. Well, no luck with that. Tmux works great, but X integration is broken somehow. I'm not going to debug it, so let's move on.

  • Second idea was how everybody seems to do it: launching tmux from my .bashrc. Done correctly, this breaks nothing - it just took a few tries to do it right.

    That's the relevant line in my .bashrc:

    [[ ${-#*i} == ${-} ]] || [ $TMUX ] || exec tmux
    

    And let's see it part by part:

    [[ ${-#*i} == ${-} ]]

    Tests for an interactive shell. If it's not interactive (that is, if the ${-} environment variable is the same as itself without the 'i' character), stops there, and go to the next line.

    [ $TMUX ]

    Tests for a tmux session. The alternaive form of [ $TERM == "screen" ] does not work because the TERM variable is sent to remote shells too. This later form will not start tmux on remote hosts when I ssh into them.

    exec tmux

    Will replace the current shell with a tmux session. Just running tmux here will send me back to the shell after I close it, that is not what I want. I want the terminal to close when I close my session.

That last approach works, for some definition of "work". I'm keeping it for now, but it will certainly require some improvement later. For now, I've got time to try a few things on it, and see how it works.

The Good

Tmux is always running now.

I get all the good things I said up there, and don't even have to think about it.

The Bad

Tmux is always running now.

How do I start a root shell without living it open to somebody stealing it? How do I attach into a different session without leaking at least one session?

To Do

So, how can I fix those problems?

I've made a quick research, and there seems to be no easy way to to that. This sucks, but looks like I need write a tmux clients manager. I'm trying to come up with a simple interface for it, if I manage to, I'll probably write one. If not, well, security is a show stopper.