May
05
2010

switching from gnu screen to tmux (updated)

update #1: upstream accepted my patch, so the next tmux release will provide window-status-alert-{attr,fg,bg} ;) Only difference is the use of alert instead of flagged. It sounds better anyway ;) I’ll adjust my patch on 1.2 as well :)

update #2 [2010/05/17]: uploaded my updated config file, now using ` as my prefix key

update #3 [2013/12/07]: a few things have changed in tmux the last few years, so I’ve uploaded my updated config :)

I gave tmux a try yesterday.

Clean config file, thorough documentation and a few nice touches here and there (i.e. better, persistent window splitting) make it a nice alternative to screen, but the biggest difference lies in memory usage. Screen can easily eat up to 40-50mb with just a few windows open, but tmux has yet to reach the 10mb mark!

You may argue that ram is cheap these days, but when you’re on a 360mb VPS ram matters ;)

I did find a few bugs/annoyances, for instance if you add set-option -g default-terminal “screen-256color” in your config file, tmux stops evaluating the #T variable.

I hacked my way out of this one by adding the following in my .bash_profile instead:

[[ $TERM == "screen" ]] && export -p TERM="screen-256color"

Turns out that’s not tmux’s fault but bash’s, I’ll have to create a patch for that as well :) If you have the same issue, you can use the above hack as a temporary fix.

Also version 1.2 does not provide a way for you to customize the colors used on window titles with alerts (either monitored or when the bell is active), but I patched that and sent it upstream ;)

You can find an ebuild with the patch in my overlay, wirelay (layman -a wirelay ;)).

The patch was accepted upstream so it’ll be in the next release.

My tmux looks like this:

and with some split panes:

finally, below is my (updated on 2013/12/07) tmux.conf config file, used in the above screenshots.

I decided to use ` as my prefix key, its really better than hitting ctrl-a all the time :P

# ` is an interesting key for a prefix
set-option -g prefix `
# set-option -g prefix C-a

 

unbind-key C-b
bind-key C-a last-window
bind-key ` last-window
bind-key a send-prefix

 

# we might need ` at some point, allow switching
# we can also send the prefix char with `-a
bind-key F11 set-option -g prefix C-a
bind-key F12 set-option -g prefix `

 

# 0 is too far from ` ;)
set -g base-index 1

 

# set-option -g default-terminal “screen-256color”
set-option -g mouse-select-pane on
set-option -g status-keys vi
set-option -g bell-action any
set-option -g set-titles on
set-option -g set-titles-string ‘#H:#S.#I.#P #W #T’ # window number,program name,active (or not)
set-option -g visual-bell off

 

setw -g mode-keys vi
setw -g mode-mouse on
setw -g monitor-activity on

 

bind e previous-window
bind f next-window
bind E swap-window -t -1
bind F swap-window -t +1
# bind j up-pane
# bind k down-pane

 

set-option -g status-utf8 on
# set-option -g status-justify centre
set-option -g status-justify left
set-option -g status-bg black
set-option -g status-fg white
set-option -g status-left-length 40
set-option -g status-right-length 80

 

set-option -g pane-active-border-fg green
set-option -g pane-active-border-bg black
set-option -g pane-border-fg white
set-option -g pane-border-bg black

 

set-option -g message-fg black
set-option -g message-bg green

 

#setw -g mode-bg black

 

setw -g window-status-bg black
setw -g window-status-current-fg green
setw -g window-status-bell-attr default
setw -g window-status-bell-fg red
setw -g window-status-content-attr default
setw -g window-status-content-fg yellow
setw -g window-status-activity-attr default
setw -g window-status-activity-fg yellow

 

set -g status-left ‘#[fg=red]#H#[fg=green]:#[fg=white]#S #[fg=green]][#[default]’

 

set -g status-interval 5

set -g status-right ‘#[fg=green]][#[fg=white] #(tmux-mem-cpu-load 5 4) #[fg=green]][ #[fg=yellow]%H:%M#[default]’

 

set -g history-limit 4096

bind r source-file ~/.tmux.conf

:)

tags: , , ,
posted in general, gentoo by Alex “wired” Alexander

Follow comments via the RSS Feed | Leave a comment | Trackback URL

46 Responses to “switching from gnu screen to tmux (updated)”

  1. Dan Douglas says:

    I gave tmux a serious effort a few months ago. There’s a few things that made me switch back to screen.

    1) Tmux doesn’t support mouse dragging. If you use Vim in Screen you can “set ttymouse=xterm2″ in .vimrc and you can drag visual selections and have them show up in your X copy buffer, and it defines a protected region for the area you actually want to select. You can even drag to resize vim’s split windows. None of that works in Tmux. If you do vertical splitting, tmux it selects text from both sides of the split, and with line numbering on it selects the numbers unless you :set nonumber. Yes, just like screen Tmux has it’s own copy/paste system – but it’s slow to use. You end up with 3 different buffers for X, Screen, and your editor and it becomes a pain especially when working from putty.

    2) Tmux handles windows very differently from screen. What Vim calls “tabs”, tmux calls “windows”, what Vim and screen call “windows”, tmux calls “panes”, and what Vim and Screen call “buffers”, tmux has no equivalent – which is has been a huge pain in the ass until possibly the latest version of Tmux which added the join-pane command which I haven’t tried since it was released. Still, I find working with it in that way a bit unnatural.

    Clearly Tmux looks like the better long-term solution. It’s configuration actually makes sense and it’s session handling are superior to screen. Screen development is stalled and the live ebuild from the berkano overlay with the vertical split patch hasn’t been building for the last 6 months or so. Since switching to xmonad as a tiling wm really the only thing I need is the detachable sessions support, which Screen does just fine.

    • wired says:

      You probably had mouse-select-pane set to on. That way, tmux grabs the mouse click. You can still hold down the shift key to mark things by clicking and dragging :) Not sure if you can make tmux define a protected region though.

      Join-pane and break-pane work as advertised in 1.2.

      I don’t use splitting much on localhost either, since I’m using the awesome window manager, but splitting is very useful when doing work over ssh :)

      • Dan Douglas says:

        Yeah splitting is definitely useful over ssh. That’s primarily why I started using it. :)

        I tried turning mouse-select-pane off. I had a chat with one of the tmux devs on irc a few months ago and apparently the problem is simply that they don’t implement that yet. My workaround was setting a hotkey in vim to turn line numbers on and off so it’s possible to copy/paste between a browser window without having to abuse xclip too much.

        I didn’t realize Screen was that hard on resources either. Kinda stinks. I’ve been using Konsole too which apparently isn’t so lightweight. I like it though since I have kde installed anyway and has always worked flawlessly.

    • Will says:

      For Vim in Tmux, you need to use ttymouse=xterm.

  2. krigstask says:

    I’ve switched to tmux recently too, but I’m not that advanced user, so the only thing bothering me is that I can’t figure out how to do something similar to `screen -RD`. If remote box has been rebooted, I don’t want to run `tmux attach`, then see it failing, run `tmux` and then reattach to it again. I think it could be somehow worked around, but didn’t succed myself.

    • wired says:

      you could define an alias (or write a small bash script) that does that automatically:

      alias mytmux="tmux a -d || tmux"

      • krigstask says:

        That’s rather messy, isn’t it? (-:E

        Probably worth filing feature request or something. I thought it’s quite common usage pattern and has already been implemented.

        (+1 for urxvt, by the way)

        • jjdkfjl says:

          thanks to nicm, here is what I use:

          #!/bin/sh
          # start tmux session with 3 windows attached (authpf+mutt+ncmpc)
          # on a separate socket with separate configuration
          # or if session 0 already exists, attach it to current terminal

          [ -n “$TMUX” ] && exit

          SOCKET=/tmp/tmux-1000-main
          CONF=”$HOME/.tmux.conf-main”
          TMUX=”tmux -S $SOCKET”

          $TMUX has -t0 2>/dev/null || $TMUX -f $CONF start
          $TMUX attach -d -t0

  3. Alex says:

    The biggest memory saving I made on my machine recently was switching away from gnome-terminal to urxvt(d). I’ve never really noticed much of a memory issue with screen although I do wish it was easier to script/configure. I shall check out tmux when I next have a spare few hours :-)

    • wired says:

      urxvt++, the best terminal out there ;)

    • ciny says:

      urxvt-unicode with tabs FTW ;)

    • ed says:

      I don’t think the switch from gnome-terminal would have saved that much. In the past I’ve used urxvt and found it slow and memory hogging along with CPU. The biggest problem I had with it was a lot of scroll lines and when resizing it does something very nice which is to reformat the lines of scroll back, but with too much history this hogs the CPU.

      gnome-terminal doesn’t do this, like most terminals but does make choosing modern fonts quite easy (something that urxvt lacks).

      In the end I just got annoyed with urxvt after about three years of solid use and now gnome-terminal is my new friend.

  4. George says:

    I can use tmux, but i can understand – how scroll history with mouse (

  5. sylware says:

    gnu screen and tmux are bloatware.

    I swtiched to dtach. http://dtach.sourceforge.net/

    • wired says:

      well, if your needs are satisfied with dtach, then sure, the others are bloatware for you! I, on the other hand, actually use their features :)

    • ed says:

      dtach is bloatware. You should switch to nohup http://en.wikipedia.org/wiki/Nohup

    • Andrew says:

      dtach is cool. But: 1) When you reconnect, you lose your screen state. dtach just sends ^L and hopes for the best. Sometimes it’s hard for me to remember what I was doing if I can’t see the screen I was working on. ;-) 2) It’s flaky. I occasionally attach to find a blank, unresponsive screen, and there’s no recovering the session at that point.

  6. I don’t know why your ‘screen’ use is bloated. This is from a 256 MiB home server:

    F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
    1 S tzot 3215 1 0 80 0 – 1319 ? May01 ? 00:00:03 SCREEN -A -a -U
    0 S tzot 32215 32214 0 80 0 – 1018 ? 11:32 pts/0 00:00:00 screen -A -a -U -D -r 321

    Its size is 100×25, four bash/dash sessions plus one mc session, no ~/.screenrc, the default /etc/screenrc has defscrollback 1000. The system runs gentoo on a Geode LX processor.

  7. chithanh says:

    If you are interested in saving even more memory, I suggest that you look at dvtm+dtach instead of tmux.

  8. fb says:

    I originally switched from screen to tmux because screen has problems with terminals larger than 256 chars in width. Maybe there are patches around, but I couldn’t find a solution back then (I don’t think they solved it until now?). Anyway, tmux works find with >256 char wide terminals :). And soon I realized how much “better” tmux is.

    nice seeing you switching to tmux too ;)

  9. ScreenSecurity says:

    tmux is cool, but I do like that I can password-protect detached sessions with screen. Yeah, it could probably be hacked, I guess, but it is an extra hurdle.

    • nm says:

      You can lock in tmux too, but because Linux has no standard terminal lock program you need to decide which you want to use and configure the lock-command option yourself, then you can use tmux lock-server/lock-session and so on.

      • Korthrun says:

        Locking is nothing like screens password protection.

        Sadly I’ve been trying to reproduce screen like behaviour for a few weeks now. I’ve even had a few people in IRC on freenode put in a good effort to help me out.

        Locking (what tmux seems to do), is like standing up from your windows workstation and hitting windows+l. The workstation is now locked. It’s unusable. You can’t manipulate another session, or existing windows etc. You cannot detach a locked tmux session/client, because your lock application has control of your terminal at that point.

        With the password protection that screen uses, you can set a per session password in each screen. You detach the session just like normal. When you attempt to reattach the session, you’re asked for a password. There is no “lock” on the terminal. You detach and are dropped back to your “real” terminal. You can attach other screens, or run other applications, and go about using your inital terminal.

        Wish I could get this behaviour in tmux =/ I’d love to replace screen with it.

        • nickaugust says:

          just detach and run vlock

        • NM says:

          tmux used to do locking internally and allow you to do per-session locking (that is, prevent reattach of that session from anywhere rather than just locking a single tty), but it is ultimately futile because a) anyone with a shall as your user can do whatever they like anyway b) “whatever they like” includes attaching to tmux with gdb and unlocking the session.

  10. ed says:

    screen is really cool, and does somethings that I’ve yet to find counterparts to with tmux, such as the -x option:

    http://www.s5h.net/wiki/Screen#Automation

    How did you measure the RAM usage? Did you have the same scrollback in tmux as screen?

    • nm says:

      The equivalent of -x is the default with tmux unless you explicitly tell it to detach other sessions. You can also create a grouped session with “tmux new -t othersession” if you want them to have different a current window.

      All of the stuff at that link is possible in tmux and is often much easier…

      • ed says:

        Ah, my mistake nm, I meant -X, which executes the following command. In particular the ‘stuff’ command in screen highly useful but I’ve spent about an hour in the tmux man page and not found an equivalent, maybe it’s there but I’m not seeing it. Sticking with screen, although I will long for the page/up and down in the window list that tmux has, but as yet, its not for me.

  11. Rik says:

    I thinks it’s a pitty tmux doesn’t support VIM mappings for the copy-mode, or the choose-window functions, as screen does. Or does anyone found out a way to enable this?

    • dominikh says:

      does vi qualify as vim in this case? if so, then:
      set-window-option -g mode-keys vi

      • Rik says:

        Ah, they DO support it! Very nice, this can be a reason for me to have tmux as replacement for screen. I’ll keep you updated :)

  12. […] switching from gnu screen to tmux […]

  13. bob says:

    Tmux installs on ubuntu easily enough, but it doesn’t seem to read the config file.

    I’ve manually installed the conf file on this this page as both ‘/etc/tmux.conf’, and in my homedir as .tmux.conf.

    According to the man page, the files should be picked up, but none of the customizations are in effect. I’ve also tried ‘tmux -f ~/.tmux.conf’, but the results are the same.

    How do I get tmux to pick up it’s conf file ?

  14. newbie says:

    I first tried screen, but didn’t like the horizontal splitting only. While searching a solution (that exists) I discovered tmux and liked it better. My main problem is probably a real newbie problem, but nevertheless bothers me:

    After some google search I found a way to switch between the console and X:
    with Ctrl-Alt-F1 and F7 if I remember well.
    But it doesnt really work, when going back to the console from X tmux and all the apps I had open are gone, there is only one shell window left.
    On ArchLinux using tmux and stumpwm – how can I use the console and an X session in parallel and switch between them back and forth?

    Excuse my ignorance, please …

  15. “switching from gnu screen to tmux (updated) | Linux~ized” ended up being a very great blog post, .
    I hope you keep composing and I’m going to keep viewing! Thanks for your effort -Jamal

  16. […] switching from gnu screen to tmux (updated) | Linux~ized […]

  17. JEP says:

    Does tmux have a nethack mode like screen does? I like getting error messages like “You kill the poor window”.

  18. […] Switching from gnu screen to tmux (by Alex Alexander) with a good .tmux.conf file […]

Leave a Reply

 
Powered by Wordpress and MySQL. Original theme by openark.org - customization by me :)