Tmux, the best choice!

We’re going to talk about terminal multiplexor! We’re talking about TMUX!!


Few months ago each one on system’s department was starting working with this multiplexor terminal and we’re so satisfied , in fact, i’ve needed write this post!

I also remember with nostalgy when I started to use “screen”, a very useful tool used to:

  • run long processes mixed the time command ( /usr/bin/time –format=”%E %S %U %P” –output=”log file”) and the other “&>>” can help us too much
  • run critical processes such as new code deploy in production environment
  • run scripts in unattended mode like a daemon, it can be the first step before to be demonized.
  • to share scripts or processes with other collegues or resume jobs from differents working shifts
  • Moreover, Terminator(Linux) and iTerm(Mac) has been the consoles used for simultaneous typing to arbitrary groups of terminals to do some tasks such as new code deployment or changes in configurations. Furthermore, you can arrange terminals in a grid for each tab, really useful!!!

    If this iTerm/Terminator features are really useful, you can imagine combine with screen features, here we have TMUX!! a few weeks ago in a very rainy sunday afternoon i learned many functionalities and features customizing my work environment, it was so productivity, i recommend for any system administrator.

    here we go:

  • use multiples tab, grouping by roles/environment the servers managed
  • split each tab in a different panels
  • send the same command or signal to all panels for a tab
  • resize for each panel quickly
  • shift from each panel or tab easily
  • no need for X11, awesome!
  • define the buffer size for each panel, you can
  • customize profiles like a template where we define tab, panels, sizes and we can use it as script
  • customize the shortcut for any action
  • I’ve attached my tmux configuration profile (~/.tmux.conf), i’m going to comment my preferit parameters:
    File: tmux.conf
    Path: $HOME/.tmux.conf

    # Alert on activity in any panel
    set -g visual-activity on
    # Set buffer size of any terminal in 10000 lines
    set -g buffer-limit 10000
    # C^B+r reload the tmux configuration without close/open tmux instances
    unbind r
    bind r source-file ~/.tmux.conf  \; display "Reloaded!"
    #C^B+a :(All) write or send signal simultaneously to all panels in a tab
    unbind a
    bind a setw synchronize-panes on
    # C^B+o :(One) write or send signal just one panel
    unbind o
    bind o setw synchronize-panes off
    # index panel and index tab start in 1, default is 0
    set -g base-index 1
    setw -g pane-base-index 1
    # Custom status bar
    # Powerline symbols: ⮂ ⮃ ⮀ ⮁ ⭤
    set -g status-utf8 on
    set -g status-left-length 32
    set -g status-right-length 150
    set -g status-interval 2
    set -g status-left '#[fg=colour15,bg=colour238,bold] #S #[fg=colour238,bg=colour234,nobold]⮀'
    set -g status-right '#[fg=colour245]⮃ %R ⮃ %d %b #[fg=colour254,bg=colour234,nobold]⮂#[fg=colour16,bg=colour254,bold] #h '
    set -g window-status-format "#[fg=white,bg=colour234] #I #W "
    set -g window-status-current-format "#[fg=colour234,bg=colour39]⮀#[fg=colour16,bg=colour39,noreverse,bold] #I ⮁ #W #F #[fg=colour39,bg=colour234,nobold]⮀"

    Here you have a script to easily use it, very powerful in any emergency if you need manage several servers
    The previous gif I show us how can I launch the script, i’ve connected to 8 nodes with the same role (magenta web servers). As you can see my script add a new tmux tab and split it in 8 panells and connect each one to different node. For run this, you must run inside one tmux console.

    Finally, the sources i’ve read:
    Zooming Tmux Panes
    Simple Remote Pairing with Wemux
    Splitting terminal with tmux
    Tmux Documentation

    Projects Links:
    Tmux Project
    Wemux Project