wiki.ipfire.org

The community-maintained documentation platform of IPFire

User Tools

Site Tools


addons:tmux:start

Tmux

Tmux is since Core 87 available as an IPFire addon.

Tmux is a so called “terminal-multiplexer” and is similar to e.g. screen which allows the user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. About the horizontal and vertical splitting of the terminal window in so-called “Panes“, different software can also be used, for example, on a real-time basis from which a quick, many-sided overview about processes can be attained. Also sessions can be terminated (“detach”) but can later be executed (“attach”) again. Moreover, Tmux can be extended with configuration files (under e.g. ~/tmux.conf) for different purposes which do not exist by default yet.

Installation

Tmux can be installed as an IPFire addon over the console with an

pakfire install tmux

or over IPFires webinterface via Pakfire

Handling

Since tmux offers a lot of features, it would sprinkle the frame in here to list everything. For a deeper look into this subject several howtos can be found in the internet but may also some ideas in this wiki.

Tmux can be started without further options with a simple

tmux

Also options can be used to start tmux with special preferences like e.g.

tmux -2 -f tmux.conf

whereby this command offers 256 colors and an individual configuration file.

Keycodes

The different processing modes can be activated about the so-called „bind-key” which is by Default [STRG] - or [CTRL]-b followed by the respective keycodes (key combination).

The keycode list is by far not complete and you are invited to extend it. It should give only an overview of some useful key combinations to use Tmux.

Section Bind-Key Keycode Resultant sign Action Commands
INFOs
[CTRL]-b [ ↑ ]-ß ? List all keys list-keys
[CTRL]-b q q List pane number and pane size display-panes
[CTRL]-b [ ↑ ]-. : Edit commands in session mode
Session Managment
[CTRL]-b s s List sessions choose-tree
[CTRL]-b [ ↑ ]-4 $ Rename current session rename-session '%%'
[CTRL]-b d d Detach from current session detach-client
[CTRL]-b r r Reload configuration file source-file /root/.tmux.conf
Windows
[CTRL]-b c c Create a new window new-window
[CTRL]-b , , Rename the current window rename-window
[CTRL]-b w w List all windows choose-window
[CTRL]-b x x Delete pane or window if one pane is left kill-pane #P
[CTRL]-b d d Dettach from the actual session detach-client
[CTRL]-b c c Add a new window new-window
[CTRL]-b 0-9 or more Changes to window with allocated number. 0 is the first window select-window -t :{NR}
[CTRL]-b [ ↑ ]-5 % Split window horizontally split-window -h
[CTRL]-b [ ↑ ]-2 Split window vertically split-window
[CTRL]-b [ → ] Change to pane on the right side
[CTRL]-b [ ← ] Change to pane on the left side
[CTRL]-b [ ↑ ] Change to pane above
[CTRL]-b [ ↓ ] Change to pane below
[CTRL]-b [ESC] [ → ] Resize active window to the right
[CTRL]-b [ESC] [ ← ] Resize active window to the left
[CTRL]-b [ESC] [ ↑ ] Resize active window higher
[CTRL]-b [ESC] [ ↓ ] Resize active window lower

Example configuration

As mentioned before, Tmux can also be used with a configuration file which can contains a lot of different functions. As a little example, which should give an overview of what it could be possible, the following configuration file can be used.

File: ~/.tmux.conf
# tmux configuration file
# can takes place for user root under ´/root/.tmux.conf .
# As a system wide configuration file in case there are more users on IPFire platform,
# you can also use /etc/tmux.conf
#######################################################################################
#
 
# set defaults
set-option -g default-shell "/bin/bash"
set-option -g default-command "bash -l"
set-option -g default-terminal "screen-256color"
#
 
# remap prefix to Control + a instead of the default Control + b to screen like style
set -g prefix C-a
unbind C-b
bind C-a send-prefix
#
 
# reload config also works while a session, please adapt it to your needs in case of a system wide configuration
bind r source-file ~/.tmux.conf \; display-message "Reload config file..."
#
 
# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on
#
 
# Set scrollback to 10000 lines
set -g history-limit 10000
#
 
# Status bar
# set color for status bar
set-option -g status-bg colour235 #base02
set-option -g status-fg yellow #yellow
set-option -g status-attr dim
# Show host name and IP address on left side of status bar
set -g status-left-length 70
set -g status-left "#[fg=green] #h - #[fg=brightred]#(curl -s https://api.ipify.org) #[fg=green]|"
 
# Define right statusbar lenght
set -g status-right-length 60
# Show value of logged on users, how much RAM is free and how much HDD space are used in /var.
set -g status-right "#[fg=green]| #[fg=yellow]Users:#[fg=brightred]#(who | wc -l)#[fg=green] - #[fg=yellow]Mem:#[fg=brightred]#(free -m | awk '/Mem:/ {print $4}')#[fg=yellow]MB Free#[fg=green] - #[fg=yellow]Use:#[fg=brightred]#(df -h | awk '/sda4/ {print $5}')#[fg=yellow]in /var "
# Center window tabs
set -g status-justify centre
#
 
# Colorize active pane
set-option -g pane-active-border-fg blue
#
 
## End tmux.conf

The functions are explained a little so you can find may a little easier your own ideas for an individual configuration. Tmux with this configuration file looks similarily like this one:

For further information of the Tmux configuration take a look at the bottom to the 'Additional informations' area.

Bash Script

There is also the possibility to arrange your own script which can makes jobs like e.g. attach to existing sessions, call your configuration file on every execution and to arrange your pane and window structure to your own needs. The following example should give an example of that.

File: /usr/bin/mux
#!/bin/bash -
 
#
# Example script has been taken from ubuntu wiki
# http://wiki.ubuntuusers.de/tmux
#####################################################
# With a little modification
#
 
SESSION=main
tmux="tmux -f /root/.tmux.conf"
 
# if the session is already running, just attach to it.
$tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
       echo "Session $SESSION already exists. Attaching."
       sleep 1
       $tmux attach -t $SESSION
       exit 0;
fi
 
# create a new session, named $SESSION, and detach from it
$tmux new-session   -d -s $SESSION
# Window 0
$tmux new-window    -t $SESSION:0
$tmux rename-window 'TrafficCheck1'
 
# Window 1
$tmux split-window -d -t 0 -v
$tmux split-window -d -t 1 -h
 
$tmux send-keys -t 0 'iftop' enter C-1
$tmux send-keys -t 1 'mtr 8.8.8.8' enter C-1
$tmux send-keys -t 2 'bwm-ng' enter C-1
 
# Window 2
$tmux new-window    -t $SESSION:1
$tmux rename-window 'TmuxYourself;-)'
 
$tmux split-window -d -t 0 -v
$tmux split-window -d -t 1 -h
$tmux split-window -d -t 0 -h
 
# Window 3
$tmux new-window    -t $SESSION:2
$tmux rename-window 'IPTraf-ng'
$tmux send-keys -t $SESSION:2 'iptraf-ng' enter C-1
 
# Select entry window
$tmux select-window -t $SESSION:0
$tmux attach -t $SESSION
 
## End of tmux script

You can place the script e.g. under /usr/bin, this script expects your configuration file under ~/.tmux.conf. If you name the script e.g. mux, you can execute it by simply type mux into the console or via ssh session. A requirement for this is that this script is executable

chmod +x {/path/scriptname}

The script arrange Tmux as in the following screenshoots shown.

Mux open up 3 windows in a session with different pane structure and content in it. The first window contains 3 different kinds of software iftop, bwm-ng and mtr. The second window quarters the window and waits for commands. The third window provides iptraf-ng. With the above configuration, the tabs in Tmux status bar but also the different panes are clickable with the mouse.

The terminal.app in OS X systems needs Simbl und MouseTerm for clicking and scrolling the Tmux window, pane and tabs.

Additional informations

Since this Addon is a community development, you can find also some discussions in the IPFire Forum - New wiki for new addon tmux where you are invited to participate :-).

There are a lot more functions and features in tmux, for further informations beneath a lot of other wikis in the internet, some of the following links may be informative.

addons/tmux/start.txt · Last modified: 2018/09/19 23:00 by Jon