π

Moving from GNU Screen to Tmux

Show Sidebar

For anybody working in a command line terminal (CLI) on UNIX/Linux, I definitely recommend using GNU Screen or tmux. In case this is new to you, please do learn why you have to use them, what those tools are providing for you. I won't teach it here (again).

I was using GNU Screen for over a decade. I use it for my zsh in any terminal environment: GNU/Linux, OS X Darwin/Terminal, or Cygwin. Unfortunately, GNU Screen does not seem to have active development any more. Seldom or no updates resulted in a "reduced" community as well.

GNU Screen worked for me quite well but I was recommended tmux for quite some time. Old habits, you know. Its community is much more active and its development cycle is a healthy one. Feature-wise there shouldn't be much difference. All of my favorite screen features are available also with tmux.

These days, I decided to give tmux a serious try.

Getting a Decent Default Configuration

Same as with vim, zsh, or GNU Screen, it is important to get a good configuration file to get decent default settings to start with.

So I used the grml config file and stored it in my home directory:

curl -Lo .tmux.conf http://git.grml.org/f/grml-etc-core/etc/tmux.conf	  

Besides many other things, it changes the default prefix to C-a which every GNU Screen user is used to. During my research phase on tmux, I found out that almost every tmux user sticks to C-a prefix as well. The default prefix C-b does seem to clash with too much other tools or it is simply not as easy to type as C-a.

Go and read the rest of the file on your own, the settings are pretty much self-explaining.

Adding My Own Settings

Then I added some config lines to overwrite defaults or add functionality according to my taste. First some visualization adoptions:

set-window-option -g window-status-fg white
setw -g window-status-current-bg brightgreen
setw -g window-status-current-fg black
set -g status-fg green
set -g status-bg black
set -g status-left "#[default]@#h#[fg=red]:#S#[fg=white] |"
set -g status-right-length 34
set -g status-right '#[fg=yellow]#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=cyan,bold]%Y-%m-%d %H:%M#[default]'	  

I prefer my windows starting with number one:

## start with windows number 1 (not 0)
set -g base-index 1	  

If a window detects some activity, I would like to get a highlighted window name for it:

# Notifying if other windows has activities
setw -g monitor-activity on	  

In case a command like rsync is running in a background window, I would like to get a highlighted window title in case the command does not produce new output any longer. I can turn on this behavior with C-a m and switch back with C-a M:

## m -> notify me on 10s of silence
bind-key m set-window-option monitor-activity off \; set-window-option monitor-silence 10
## M -> notify me on activity again (as usual)
bind-key M set-window-option monitor-activity on \; set-window-option monitor-silence 0	  

Finally, I do have some frequently used tools I use:

bind-key E new-window -a -n "mutt" -t 1 "/usr/bin/mutt"
bind-key T new-window -a -n "TUG" -t 2 "/usr/bin/slrn -h news.tu-graz.ac.at"
bind-key G new-window -a -n "gmane" -t 3 "/usr/bin/slrn -n -h news.gmane.org"
bind-key P new-window -a -n "procmail" -t 1 "/usr/bin/vim /home/karl/.procmailrc"
bind-key I new-window -a -n "IRC" -t 1 "/usr/bin/irssi"	  

Keyboard Shortcuts

Here is a table with the keyboard shortcuts I was using with GNU Screen and how they work in tmux:

GNU screen tmux Command configuration/notes
screen -s MYSESSION tmux new -s MYSESSION start
C-a d C-a d detach tmux
screen -r tmux a re-attach detached session
screen -DD -R tmux a re-attach attached session
C-a c C-a c create new window
C-a C-a C-a C-a last window bind-key C-a last-window
C-a n C-a n next window
C-a p C-a p previous window
C-a ESC C-a PageUp copy mode
C-r C-r copy mode: search backward
arrows arrows copy mode: move cursor
SPC C-a SPC copy mode: begin mark
SPC C-a RET copy mode: end mark
ESC q exit copy mode
C-a ] C-a = paste from copy mode
C-a [0-9] C-a [0-9] goto window [0-9]
C-a M :setw monitor-activity on toggle activity monitor
:setw monitor-silence 30 toggle inactivity monitor
C-a w C-a w list windows
C-a a C-a a send C-a
C-a : movew -s 2 -t 1 move window 2 to pos. 1
C-a : movew -r renumber all windows only for newer tmux versions
C-a ? C-a ? help
C-a E C-a E start email see config lines above
C-a G C-a G start gmane slrn see config lines above
C-a T C-a T start tu-graz slrn see config lines above
C-a P C-a P start edit procmail see config lines above

Stuff That I Could Not Accomplish so Far

As with my GNU Screen, I'd like to get Control a with C-a a:

## "C-a a" sends C-a
bind-key a  send-prefix	  

Unfortunately, this does not seem to work.

Sadly, I was not able to start those tools in a new tmux automatically. The whole session startup configuration I could not understand so far. Some lines resulting from my tests are:

## startup
# new-session -d
# #new-session "vk-default"
# new -a -n "mutt" -t 2 "/usr/bin/mutt"
# new-window -a -n "TUG" -t 3 "/usr/bin/slrn -h news.tu-graz.ac.at"
# #new-window -a -n "gmane" -t 4 "/usr/bin/slrn -n -h news.gmane.org"	  

Another thing I could not understand so far is the behavior how new windows are created. In GNU Screen, I could define that C-a E is opening my email tool as window 2 or the next free number after 2. With tmux, this is somehow different. tmux is inserting the new window as number 2, re-numbering all windows above.

In case you can help me with one or more issues above, please drop a comment below!

Summary

So far, the transition from GNU Screen to tmux was a smooth one. Almost everything works the same way in both tools.

I was positively pleased that I don't have to do screen -DD -R (forcefully detach and re-attach) a session any more when I forgot to detach it on the other machine. With tmux, I can attach to an already attached session as well!

In case you're still running GNU Screen, invest an hour or so in the upcoming holidays and switch to the more active tmux. It's not really that hard as I thought it would be.

Please do also consider reading the comments related to this posting on reddit.

Comment via email or via Disqus comments below: