Categories
SysOps

How to create basic tmux setup

I am using tmux terminal multiplexer daily. It is an irreplaceable utility that eases everyday tasks as it lets you switch between multiple applications in one terminal. I will briefly describe my personal configuration setup.

tmux

Brief description

Unbind the default C-b prefix.

unbind-key C-b

Define ` backtick as prefix.

set -g prefix `

Send ` backtick to the application after typing it twice.

bind-key ` send-prefix

Set to zero the time for which tmux waits after an escape is input to determine if it is part of a function or meta key sequence. By default, it is 500ms.

set -g escape-time 0

Ensure that prefix will not be triggered on paste. This definition is redundant.

set -g assume-paste-time 1

Use prefix r to read and process configuration.

bind r source-file ~/.tmux.conf \; display "Configuration executed"

Start counting windows from 1.

set -g base-index 1

Start counting panes from 1.

set-window-option -g pane-base-index 1

Define the left part of the status bar as one empty character for better readability.

set -g status-left " "

Define the right part of the status bar as session hostname time.

set -g status-right "#[fg=colour088]#S #[fg=colour232]#h #[fg=colour255]%r"

Justify the window list to the left. This definition is redundant.

set -g status-justify left

Do not monitor for activity and silence by default, as I prefer per window settings.

set-window-option -g monitor-activity off
set-window-option -g monitor-silence 0

Do not display messages about silence, bell, and activity.

set -g visual-activity off
set -g visual-bell off
set -g visual-silence off

Define activity and bell style.

set -g window-status-activity-style 'bg=colour031,fg=colour048'
set -g window-status-bell-style     'bg=colour031,fg=colour088'

Define key bindings for easy activity/silence window monitoring.

bind-key M-a set-window-option monitor-activity on  ; display "Monitoring window for activity"
bind-key M-A set-window-option monitor-activity off ; display "NOT monitoring window for activity"
bind-key M-s set-window-option monitor-silence 15   ; display "Monitoring window for silence"
bind-key M-S set-window-option monitor-silence 0    ; display "NOT monitoring window for silence"

Set the default terminal type.

set -g default-terminal "screen-256color"

Set status bar color.

set -g status-bg colour031

Set messages color.

set -g message-fg colour232
set -g message-bg colour031

Set window status colors.

set-window-option -g window-status-fg colour232
set-window-option -g window-status-bg colour031
set-window-option -g window-status-current-fg colour255
set-window-option -g window-status-current-bg colour031

Set panel border colors.

set -g pane-border-fg colour235
set -g pane-active-border-fg colour255

Use vi keys in copy and choice modes.

set-window-option -g mode-keys vi

Configure clock.

setw -g clock-mode-colour colour031
setw -g clock-mode-style 24

Configuration file

My personal ~/.tmux.conf configuration file.

# Personal tmux configuration
#
# Source: https://sleeplessbeastie.eu/2016/08/22/personal-tmux-configuration/
#
#
# color         code       used for
# black         colour000  currently commented out
# bright green  colour048  activity/silence window trigger
# dark red      colour088  bell window trigger
# grey          colour232  inactive window status, message text
# almost black  colour235  pane inactive border, hostname in status
# white         colour255  current window status, pane active border, current time in status
# blue          colour031  window status background, message background, status background, clock
#
# Some color definitions are commented out to work flawlessly on different terminal profiles
#
# unbind the default prefix
unbind-key C-b
# set backtick as prefix
set -g prefix `
# type backtick twice to send it to the application
bind-key ` send-prefix
# tweak escape time
set -g escape-time 0
# ensure that prefix will be not triggered on paste
set -g assume-paste-time 1
# use prefix r to reload configuration
bind-key r source-file ~/.tmux.conf ; display "Configuration reloaded"
# start counting windows from 1
set -g base-index 1
# start counting panes from 1
set-window-option -g pane-base-index 1
# define left part of the status bar as one empty character for better readability
set -g status-left " "
# define right part of the status bar as session, hostname and time
set -g status-right "#[fg=colour088]#S #[fg=colour232]#h #[fg=colour255]%r"
# justify window list to the left
set -g status-justify left
# do not monitor for activity and silence by default
set-window-option -g monitor-activity off
set-window-option -g monitor-silence 0
# do not display messages about silence, bell and activity
set -g visual-activity off
set -g visual-bell on
set -g visual-silence off
# define activity and bell style
set -g window-status-activity-style 'bg=colour031,fg=colour048'
set -g window-status-bell-style     'bg=colour031,fg=colour088'
# define keys for easy activity/silence monitoring
bind-key M-a set-window-option monitor-activity on  ; display "Monitoring window for activity"
bind-key M-A set-window-option monitor-activity off ; display "NOT monitoring window for activity"
bind-key M-s set-window-option monitor-silence 15   ; display "Monitoring window for silence"
bind-key M-S set-window-option monitor-silence 0    ; display "NOT monitoring window for silence"
# set default terminal type
set -g default-terminal "screen-256color"
# set status bar colors
#set -g status-fg colour255
set -g status-bg colour031
#set -g status-attr bright
# set messages color
set -g message-fg colour232
set -g message-bg colour031
#set -g message-attr bright
# set bottom window status colors
set-window-option -g window-status-fg colour232
set-window-option -g window-status-bg colour031
#set-window-option -g window-status-attr bright
set-window-option -g window-status-current-fg colour255
set-window-option -g window-status-current-bg colour031
#set-window-option -g window-status-current-attr bright
# set panel border colors
set -g pane-border-fg colour235
#set -g pane-border-bg colour000
set -g pane-active-border-fg colour255
#set -g pane-active-border-bg colour000
# use vi keys in copy and choice modes
set-window-option -g mode-keys vi
# Clock
setw -g clock-mode-colour colour031
setw -g clock-mode-style 24

Additional notes

I can strongly recommend tmux – Productive Mouse-Free Development book for those who want more information on this topic.

Update 14.11.2020

Please note that tmux style options changed over time.