Saturday, October 12, 2013

Setting up tmux - terminal multiplexer

Tmux stands for terminal multiplexer and it provides similar functionality as GNU Screen, it multiplies terminal sessions. It has slightly different philosophy of inner functionality as screen (it has been designed as client-server program) and it handles few things better than screen (see FAQ for more details).


I have used screen for few years before I've discovered tmux, so for me the crucial functionality was the ability to configure basic shortcuts I've used in screen. So the tweaking had begun and after a while, tmux was ready to replace my screen.
Here's how it looks:

In the above picture, you can see tmux session named 3 and it has 4 tabs opened, currently showing tab 2 (colored white)  which is split into 3 sections and indicating activity in tab 0 (colored green).

Tmux uses main configuration file /etc/tmux.conf, that's where I've made all changes, mainly set CTRL-a as the bind key shortcut. Following example is my tmux.conf.
#/etc/tmux.conf
# change default bind key
unbind C-b
set -g prefix C-a

# color tuning
setw -g window-status-current-bg white
setw -g window-status-current-fg black
set-option -g status-bg black
set-option -g status-fg green
set-option -g status-attr bold

# set custom bindings
bind-key C-a last-window
bind-key a send-prefix
bind-key -n S-right next
bind-key -n S-left previous-window
bind-key -n C-left swap-window -t -1
bind-key -n C-right swap-window -t +1

# extend scrollback size
set -g history-limit 50000

# statusline tunning
set-window-option -g status-right '"#22T" %H:%M:%S %d.%B'
set-window-option -g status-interval 1

# select panes with a mouse
set-option -g mouse-select-pane on

# other settings
setw -g aggressive-resize on
set -g default-terminal "screen-256color"
set -g monitor-activity on
set -g history-limit 4096

# No bell for current window, unobstrusive bell in statusbar for others.
set -g bell-action none
set -g visual-bell on

# better splits with | and -
bind-key | split-window -h
bind-key - split-window -v

# UTF-8
setw -g utf8 on

# Keep messages on screen a bit longer
set -g display-time 1500
set -g display-panes-time 1500

# join pane
bind @ command-prompt -p "create pane from:" "join-pane -s ':%%'"

and a short list of commonly used shortcuts:
TMUX

list-session (ls)
new-session (new) [-s session-name]
attach [-dr] [-t target-session]
        -d              detach any other client
        -r              read-only
        
--------------------------------------------------------------

C-o             rotate the panes
C-a SEQ

SEQ:
PgUp    start copy mode
!       break current pane out of the window
@       join pane to the window
- (")   split current pane horizontally
| (%)   split current pane vertically
;       move to previous active pane
x       kill current pane
{       swap current pane with previous
}       swap current pane with next
Arrow   change to the pane according to arrow direction
C-Arrow resize current pane (1 step)
A-Arrow resize current pane (5 steps)
q       show pane numbers + NR to jump

$       rename tmux session
&       kill current window
'       jump to window
,       rename window
.       move window (index number must be not used)
0-9     jump to window
w       list all windows
:       enter the tmux command prompt
d       detach current session
D       select session to detach
s       select session to be attached to current client
L       switch to previous session
c       new window
f       find in open windows
C-a (l)   move to previously selected window
n       next window
p       previous window
r       force redraw
t       show the time

~       show previous messages from tmux
i       info about window
?       list keybindings

--------------------------------------------------------------

No comments:

Post a Comment