Running a terminal multiplexer

Discussion in 'Tutorials and Guides' started by wlanboy, Mar 12, 2014.

  1. wlanboy

    wlanboy Content Contributer

    2,126
    1,169
    May 16, 2013
    I found a little gem that I am using if I have to do serveral things at the same time on the same server.
    Like testing my scripts and looking at the logs and at the mongodb client at the same time.

    The tool is tmux which is a terminal multiplexer.

    It allows you to split a terminal into smaller peaces and to navigate between the peaces and whole panes.

    Installation is simple:


    apt-get install tmux

    You can start the tool with "tmux".
    After that you can split your screen with following commands
    Split vertical:


    Ctrl-b %

    screen1.jpg
    Split horizontal:


    Ctrl-b "

    screen2.jpg
    Or both:
    screen3.jpg

    You can navigate between the different panes with:


    Ctrl-b o

    You can add a new page too:


    Ctrl-b c

    And switch between them with:


    Ctrl-b n

    screen4.jpg
    You can change the title of one screen too by:


    Ctrl-b ,

    Like screen you can detach and attach to running sessions:
    List sessions:


    tmux list-sessions

    Detach session:


    Ctrl-b d

    Attach session:


    tmux attach -t [session name]

    Best of all is the configuration of tmux itself:


    nano ~/.tmux.conf

    Content:

    Code:
    # Start numbering of windows at 1
    set -g base-index 1
    
    # Set up a status bar
    set -g status-bg black
    set -g status-fg white
    set -g status-left "#[fg=green]"
    set -g status-right "#[fg=green]#H"
    #Or a shell command
    #set -g status-right "#[fg=yellow]#(uptime)"
    
    # Highlight active window
    set-window-option -g window-status-current-bg red
    
    # Set clipboard and history limit
    set-option -g set-clipboard on
    set -g history-limit 1000
    
    # Set modifier from Ctrl+b to Ctrl+a, just like screen (fisle)
    set-option -g prefix C-a 
    
    # mouse support (dabtech)
    set -g mode-mouse on
    set -g mouse-resize-pane on
    set -g mouse-select-pane on
    set -g mouse-select-window on
    
     
    Last edited by a moderator: Mar 13, 2014
    peterw and fisle like this.
  2. fisle

    fisle Active Member

    151
    71
    May 16, 2013
    My favourite config options:

    Code:
    set-option -g prefix C-a  # Set modifier from Ctrl+b to Ctrl+a, just like screen
    
    unbind ^A 
    
    bind ^A last-window  # Press Ctrl+A twice and it switches to previously active window
     
    wlanboy likes this.
  3. wlanboy

    wlanboy Content Contributer

    2,126
    1,169
    May 16, 2013
    Added it to my post.
     
  4. peterw

    peterw New Member

    800
    189
    Jun 14, 2013
    Tmux is nice but I use the lightweight dvtm.

    New window: Ctrl-g + c

    Close window: Ctrl-g + x

    Next window: Ctrl-g + j

    Previous window: Ctrl-g + k
     
  5. dabtech

    dabtech New Member

    9
    7
    Feb 1, 2014
    Mouse support can also be added, so panes can be selected via mouse clicks and resized by grabbing borders.

    Code:
    set -g mode-mouse on
    set -g mouse-resize-pane on
    set -g mouse-select-pane on
    set -g mouse-select-window on
    
     
    wlanboy likes this.
  6. wlanboy

    wlanboy Content Contributer

    2,126
    1,169
    May 16, 2013
    Added it to my post.
     
  7. telephone

    telephone New Member

    190
    260
    May 16, 2013
    The config file should be:

    Code:
    ~/.tmux.conf
     
    wlanboy likes this.
  8. Shados

    Shados Professional Snake Miner

    213
    47
    May 15, 2013
    If you're using tmux now, you may also want to check out Byobu - it has some nice enhancements built on top of tmux/screen :).
     
    wlanboy likes this.
  9. wlanboy

    wlanboy Content Contributer

    2,126
    1,169
    May 16, 2013
    Yup - my 11,6" screen ate that point - fixed.

    It is nice but wasting some space.

    Do you know how to split screens with Byobu?