-
LINUX > tmux
INSTALLATION
apt install tmux
SESSIONS
Créer une session :
tmuxNommer la session qui va être créée :
tmux new -s sessionSe rattacher à la dernière session utilisée :
tmux attachListe des sessions actives :
tmux lsS’attacher à une sessions tmux ou X est le numéro de la session :
tmux attach -t XRACCOURCIS CLAVIER
[
CTRL] + [B] puiscCréer un nouveau terminal&Killer la fenêtre courante et tous les panels qu’elle contient
p|nFenêtre précédente/suivantenuméroChoisir un terminal (numéro du terminal)
dDétacher la session
,Renommer un terminal
wAfficher la liste des terminaux disponibles
tAfficher l’heure dans un terminalxkiller le panel!séparer le panel de la fenêtre (l’envoie vers une nouvelle fenêtre)sswitcher de session interactivementDans un Split :
"Split vertical du terminal courant en deux + ouverture d’un terminal dans le nouveau panel
%Split horizontal du terminal courant en deux + ouverture d’un terminal dans le nouveau panel
oSwitcher entre les terminaux splittés
espaceChanger l’organisation visuelle des terminaux splittés
Alt+ (flèches directionnelles) Reduire, agrandir fenêtre du split
!Convertir un split en terminal seul
qAfficher les numéros des terminaux splittés
:joinpermet de joindre un terminal seul sans un splitExemple pour rajouter le terminal numéro 3 verticalement et pour qu’il prenne 50% de l’espace total:
:joinp -v -s 3.0 -p 50
-hou-v: horizontalement ou verticalement
-s 0.0: terminal 0 et volet 0 (volet si écran splitté)
-p 50: occupation à 50% de la fenêtreChanger les raccourcis claviers
Changer CTRL + B par CTRL + A :
set -g prefix C-a unbind C-b bind C-a send-prefix
[ CTRL ] + [ → ou ← ] pour naviguer entre les terminaux :
bind-key -n C-right next
bind-key -n C-left prev[ ALT ] + [ ← ou ↑ ou → ou ↓ ] pour naviguer entre les splits :
bind-key -n M-left select-pane -L
bind-key -n M-right select-pane -R
bind-key -n M-up select-pane -U
bind-key -n M-down select-pane -DTouches [
Fx] pour un panneau x :bind -n F1 select-window -t 1 bind -n F2 select-window -t 2 bind -n F3 select-window -t 3 bind -n F4 select-window -t 4 bind -n F5 select-window -t 5 bind -n F6 select-window -t 6 bind -n F7 select-window -t 7 bind -n F8 select-window -t 8 bind -n F9 select-window -t 9
CONFIGURATION
Le fichier conf
/etc/tmux.confpour tous les utilisateurs.home/toto/.tmux.confpour l’utilisateur toto.Pour recharger la config :
source-file ~/.tmux.conf
Pour éviter de redémarrer tmux à chaque modification, le premier truc à mettre dans ce fichier conf est de pouvoir recharger la config sans redémarrer avec la touche
rpar exemple :bind r source-file ~/.tmux.conf
Souris
Dans le fichier tmux.conf
set -g mouse on
ATTENTION : En configurant la souris, celle-ci n’est plus fonctionnelle pour le copier/coller, ni pour sélectionner du texte.
Pour retrouver cette fonctionnalité, il faudra faire [
SHIFT] + SOURIS.Graphismes
Panneaux non actif en gris :
set -g pane-border-fg colour244
set -g pane-border-bg defaultPanneau actif en rouge
set -g pane-active-border-fg colour124
set -g pane-active-border-bg defaultBarre de status en gris
set -g status-fg colour235
set -g status-bg colour250
set -g status-attr dimRecharger le fichier de config
Depuis tmux : [
CTRL] + [B] puis [:]. Puis taper : :source-file ~/.tmux.confDepuis le shell : tmux source-file ~/.tmux.conf
Autres
Faire commencer le numéro des fenêtres par 1 et non 0 :
set -g base-index 1Mettre la date à droite de la barre de status ; set -g status-right "#(uptime|awk ‘{print $11}’) #(date)"
Propriétés de la barre de status set -g display-time 3000 set -g status-bg black set -g status-fg cyan set-window-option -g window-status-current-attr bright,reverse set-window-option -g window-status-current-bg cyan set-window-option -g window-status-current-fg black
https://gist.github.com/MohamedAlaa/2961058
———
Pour séparer en deux verticalement (|) et horizontalement (-)
bind | split-window -h bind - split-window -v unbind '"' unbind %
Fast Pane-Switching
se déplacer dans les panneaux avec ALT+FLECHES
bind -n M-Left select-pane -L bind -n M-Right select-pane -R bind -n M-Up select-pane -U bind -n M-Down select-pane -D
Changing the look of tmux
# panes set -g pane-border-fg black set -g pane-active-border-fg brightred #window mode setw -g mode-bg colour6 setw -g mode-fg colour0 # window status setw -g window-status-format " #F#I:#W#F " setw -g window-status-current-format " #F#I:#W#F " setw -g window-status-format "#[fg=magenta]#[bg=black] #I #[bg=cyan]#[fg=colour8] #W " setw -g window-status-current-format "#[bg=brightmagenta]#[fg=colour8] #I #[fg=colour8]#[bg=colour14] #W " setw -g window-status-current-bg colour0 setw -g window-status-current-fg colour11 setw -g window-status-current-attr dim setw -g window-status-bg green setw -g window-status-fg black setw -g window-status-attr reverse # Info on left set -g status-left '' # loud or quiet? set-option -g visual-activity off set-option -g visual-bell off set-option -g visual-silence off set-window-option -g monitor-activity off set-option -g bell-action none set -g default-terminal "screen-256color" # The modes setw -g clock-mode-colour colour135 setw -g mode-attr bold setw -g mode-fg colour196 setw -g mode-bg colour238 # The panes set -g pane-border-bg colour235 set -g pane-border-fg colour238 set -g pane-active-border-bg colour236 set -g pane-active-border-fg colour51 # The statusbar set -g status-position bottom set -g status-bg colour234 set -g status-fg colour137 set -g status-attr dim set -g status-left '' set -g status-right '#[fg=colour233,bg=colour241,bold] %d/%m #[fg=colour233,bg=colour245,bold] %H:%M:%S ' set -g status-right-length 50 set -g status-left-length 20 setw -g window-status-current-fg colour81 setw -g window-status-current-bg colour238 setw -g window-status-current-attr bold setw -g window-status-current-format ' #I#[fg=colour250]:#[fg=colour255]#W#[fg=colour50]#F ' setw -g window-status-fg colour138 setw -g window-status-bg colour235 setw -g window-status-attr none setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F ' setw -g window-status-bell-attr bold setw -g window-status-bell-fg colour255 setw -g window-status-bell-bg colour1 # The messages set -g message-attr bold set -g message-fg colour232 set -g message-bg colour166
—
To view the list of open Tmux sessions, run:
tmux ls
You can attach to the last created session by running this command:
tmux a
If you want to attach to any specific named session, for example "ostechnix", run:
tmux attach -t ostechnix
Or, shortly:
tmux a -t ostechnix
Kill Tmux sessions
When you’re done and no longer required a Tmux session, you can kill it at any time with command:
tmux kill-session -t ostechnix
To kill when attached, press Ctrl+b and x. Hit "y" to kill the session.
You can verify if the session is closed with "tmux ls" command.
To Kill Tmux server along with all Tmux sessions, run:
tmux kill-server
Be careful! This will terminate all Tmux sessions even if there are any running jobs inside the sessions without any warning.
When there were no running Tmux sessions, you will see the following output:
$ tmux ls no server running on /tmp/tmux-1000/default
Split Tmux Session Windows
Tmux has an option to split a single Tmux session window into multiple smaller windows called Tmux panes. This way we can run different programs on each pane and interact with all of them simultaneously. Each pane can be resized, moved and closed without affecting the other panes. We can split a Tmux window either horizontally or vertically or both at once.
Split panes horizontally
To split a pane horizontally, press Ctrl+b and " (single quotation mark).
Use the same key combination to split the panes further.
Split panes vertically
To split a pane vertically, press Ctrl+b and %.
Split panes horizontally and vertically
We can also split a pane horizontally and vertically at the same time. Take a look at the following screenshot.
First, I did a horizontal split by pressing Ctrl+b " and then split the lower pane vertically by pressing Ctrl+b %.
As you see in the above screenshot, I am running three different programs on each pane.
Switch between panes
To switch between panes, press Ctrl+b and Arrow keys (Left, Right, Up, Down).
Send commands to all panes
In the previous example, we run three different commands on each pane. However, it is also possible to run send the same commands to all panes at once.
To do so, press Ctrl+b and type the following command and hit ENTER:
:setw synchronize-panes
Now type any command on any pane. You will see that the same command is reflected on all panes.
Swap panes : To swap panes, press Ctrl+b and o.
Show pane numbers : Press Ctrl+b and q to show pane numbers.
Kill panes : To kill a pane, type exit + [ENTER] ou bien CTRL+B and X. , puis confirmer en tapant y.
CTRL+D for pane/session close. No need to kill somebody
CHEATSHEET
Commands
tmux -u # UTF8 mode tmux -S ~/.tmux.socket
Sessions
tmux new tmux new -s session_name tmux attach # Default session tmux attach -t session_name tmux switch -t session_name tmux ls # List sessions tmux detach
Windows
tmux new-window
Help
C-b ?
Scrolling
C-b [ # Enter scroll mode then press up and down
Copy/paste
C-b [ # 1. Enter scroll mode first. Space # 2. Start selecting and move around. Enter # 3. Press enter to copy. C-b ] # Paste
Panes
C-b % # vert C-b " # horiz C-b hkjl # navigation C-b HJKL # resize C-b o # next window C-b q # show pane numbers C-b x # close pane C-b { or } # move windows around
Windows
C-b c # New window C-b 1 # Go to window 1 C-b n # Go to next window C-b p # Go to previous window C-b w # List all window
Detach/attach
C-b d # Detach C-b ( ) # Switch through sessions tmux attach
Niceties
C-b t # Time
Status formats
setw -g window-status-format `#[fg=8,bg=default]#I`
See message-command-style in the man page.
Attribute/colors
#[fg=1] standard color
#[fg=yellow] yellow
#[bold] bold
#[fg=colour240] 256 color
#[fg=default] default
#[fg=1,bg=2] combinations
#[default] reset
black red green yellow blue magenta cyan white - colour0 … colour255 - #333 (rgb hex)
bold underscore blink noreverse hidden dim italics
Variables
#(date) shell command #I window index #S session name #W window name #F window flags #H Hostname #h Hostname, short #D pane id #P pane index #T pane title Options
set -g status-justify [left|centre|right] set -g status-left '...' setw -g window-status-style setw -g window-status-activity-style setw -g window-status-bell-style setw -g window-status-content-style setw -g window-status-current-style setw -g window-status-last-style setw -g window-status-format setw -g window-status-current-format setw -g window-status-separator