8/14/25

Intro

description

tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached

Using tmux

Setup

  • install tmux
sudo apt update
sudo apt install tmux

Activate mouse support

  • Enable mouse mode
set -g mouse on

Configure tmux

  • Create a /tmux.conf file that tmux runs when tmux server is started
nano ~/.tmux.conf
  • Example: Add command for mouse support
# Enable mouse mode
set -g mouse on
  • Apply changes
tmux source-file ~/.tmux.conf

Useful commands

  • start tmux
tmux
  • Detach from session
Ctrl+B then D
  • list active tmux sessions
tmux ls
0: 1 windows (created Thu Aug 14 21:43:07 2025)
  • reattach
$ tmux attach -t 0
 
  • Single line command to start 4 panes
tmux kill-session -t dev 2>/dev/null; tmux new-session -s dev -n dev \; split-window -h \; split-window -v -t 0 \; split-window -v -t 1 \; select-layout tiled \; select-pane -t 0
  • Result
+-------+-------+
| pane0 | pane1 |
+-------+-------+
| pane2 | pane3 |
+-------+-------+

Keybindings

Keybindings

Key CombinationDescription
Ctrl+B DDetach from the current session
Ctrl+B %Split the window into two panes horizontally
Ctrl+B “Split the window into two panes vertically
Ctrl+B Arrow Key (← ↑ ↓ →)Move between panes
Ctrl+B XClose pane
Ctrl+B CCreate a new window
Ctrl+B N / Ctrl+B PMove to the next or previous window
Ctrl+B 0 (1,2…)Move to a specific window by number
Ctrl+B :Enter the command line (tab completion available)
Ctrl+B ?View all keybindings (press Q to exit)
Ctrl+B WOpen a panel to navigate across windows in multiple sessions

Sample workflow

  • start session
tmux
  • split screen verically
Ctrl+b % 
  • split screen horizontally
Ctrl+b " 
  • run commands in each pane independently

8/31/25

Tmux bash scripts

WSL

  • Create ~/bin directory in WSL2 for user-specific scripts 1 and cd into it
mkdir -p ~/bin && cd ~/bin
  • Add ~/bin to PATH in WSL
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
  • Reload shell
source ~/.bashrc
  • Create a dev bash script [^2] to start tmux with 4 evenly-split panes
#!/bin/bash
tmux kill-session -t dev 2>/dev/null
SESSION="dev"
# Start a new tmux session in detached mode
tmux new-session -d -s $SESSION
# Split the window horizontally (Pane 1)
tmux split-window -h -t $SESSION
# Split Pane 0 vertically (Pane 2)
tmux split-window -v -t $SESSION:0.0
# Split Pane 1 vertically (Pane 3)
tmux split-window -v -t $SESSION:0.1
# Apply the 'tiled' layout to arrange panes evenly
tmux select-layout -t dev tiled
# Focus back on Pane 0
tmux select-pane -t $SESSION:0.0
# Attach to the session
tmux attach-session -t $SESSION
  • Make executable
chmod +x dev
  • Run script
dev
  • Resulting layout
+---------+---------+
| Pane 0  | Pane 1  |
|         |         |
+---------+---------+
| Pane 2  | Pane 3  |
|         |         |
+---------+---------+
  • Kill the session (or press Ctrl + D to exit each pane)
tmux kill-session -t dev

Use bash script in Docker

  • Add \bin directory to docker-compose.yml as a volume mount
    volumes:
      - ~/bin:/root/bin
  • Inside NoVNC, add /root/bin to PATH
echo 'export PATH="/root/bin:$PATH"' >> ~/.bashrc
  • Run script
dev
  • Resulting layout picture 36

Related

Footnotes

  1. https://www.reddit.com/r/bash/comments/hemkuv/where_do_you_store_your_bash_scripts/ [^2] Bash Scripts for tmux