goodbye screen, hello tmux

I've been a screen user for longer than I seem to remember. To me it's very powerful to leave my session running (often with long running commands) and being able to just hop right back in and continue where I left off. Screen has been awesome for me, but there have been some things that just annoy me. My biggest gripe is the naming of the tabs. I've tried a bout a dozen different things to set the titles automatically, such as when I SSH from the screen session to another host (I do that *LOT*). I always end up having to set it manually or try and just remember what was where. Well, I had another episode where I goofed up on tab names and decided that there had to be a better way. That way appears to be tmux.

Now, when you start trolling google land for alternatives to screen and comparisons between screen and tmux, you'll find a lot. Often there are complains about the lack of stewardship that screen has received and issues with it. That's really not a big one for me as long as it works. After all another way to look at unchanging code is stability. However, tmux seems to have everything I liked in screen but also makes some things like setting a title much much easier.

So, here is my new setup.

First install tmux. On Ubuntu you can just run:

sudo apt-get install tmux

There are a few things I like to have in my terminal multiplexer such as a large scroll back buffer etc. My .tmux.conf which I largely adopted from the internet, looks like this:

# Allow xterm titles in terminal window, terminal scrolling with scrollbar, and setting overrides of C-Up, C-Down, C-Left, C-Right
set -g terminal-overrides "xterm*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"

# Scroll History
set -g history-limit 15000

# Set ability to capture on start and restore on exit window data when running an application
setw -g alternate-screen on

# Lower escape timing from 500ms to 50ms for quicker response to scroll-buffer access.
set -s escape-time 50

Now to make colors and naming work, I did a little bit of stuff to my .bashrc file. First I make sure that my terminal is set to xterm-256color, but only if I'm not running in tmux, which wants the TERM to be set to screen:

if [ $TERM == "xterm" ] && [ $COLORTERM == "gnome-terminal" ]; then
        echo hello $TERM $COLORTERM
        export TERM=xterm-256color

When tmux starts up it sees the proper TERM and knows how to make everything look right, but since gnome-terminal sets it's TERM=xterm I needed to correct it so that that tmux gets the colors right.

Then to make sure the window titles in tmux turn out right as I SSH around, I do this:

case $TERM in
        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}\007"'
        export PROMPT_COMMAND
      TITLE=$(hostname -s)                                                      
      PROMPT_COMMAND='/bin/echo -ne "\033k${TITLE}\033\\"'                      
      export PROMPT_COMMAND

That will set the title right for me in the gnome-terminal, but once inside tmux, I get the hostname in the window title.

One thing worth noting is that this will continue to reset the window title to the hostname, if I want to override it I can now just set the TITLE to whatever I need it to be.

The last thing to watch out for is the Profile Setting for gnome-terminal. The mouse will scroll the command history rather than the terminal, which is what I want. To make sure I can use my scroll wheel you have to uncheck the "Use keystrokes to scroll on alternate screen" on the "Scrolling" tab in the "Profile Preferences" for gnome-terminal.

That will make things much easier for me.

Here are a couple of the interesting links I came across:



then it scrolls oddly

When I use the -ga I end up with the mouse wheel scrolling through the shell history rather than the buffer, which I prefer.