tmux Scripting, Formats, and Automation

tmux commands for listing state, using format strings, conditional logic, send-keys automation, and repeatable workspace bootstrapping.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Listing and formats

Query tmux state and build scripts with format strings.

List windows with a custom format

Print a compact machine-friendly window summary.

bashANYtmuxlist-windowsformats
bash
tmux list-windows -F "#{session_name}:#{window_index}:#{window_name}:#{window_active}"
Notes

Format strings make tmux scripts much easier to automate.

List panes with path and command

Inspect pane metadata.

bashANYtmuxlist-panesformats
bash
tmux list-panes -a -F "#{session_name}:#{window_index}.#{pane_index} #{pane_current_path} #{pane_current_command}"
Notes

Useful when scripting workspace reports or dashboards.

Print a format string

Evaluate a format without changing the UI.

bashANYtmuxdisplay-messageformats
bash
tmux display-message -p "#{client_termname} #{session_name} #{pane_id}"
Notes

Great for shell scripts that need a few tmux facts.

Conditionally run a command

Branch based on shell command success.

bashANYtmuxif-shellscripting
bash
tmux if-shell "test -f package.json" "display-message "node project""
Notes

Lets tmux scripts adapt to the current project.

Run an external shell command

Execute shell logic from tmux.

bashANYtmuxrun-shell
bash
tmux run-shell "~/.tmux/scripts/session-bootstrap.sh"
Notes

Useful for project bootstrapping and hooks.

Repeatable workspaces

Reusable patterns for bootstrapping projects.

Build a session in the background

Create a detached session before laying out windows.

bashANYtmuxworkspacedetached
bash
tmux new-session -d -s api -n editor
Notes

Detached creation is the foundation for repeatable startup scripts.

Send a command into a pane

Programmatically run startup commands.

bashANYtmuxsend-keysautomation
bash
tmux send-keys -t api:editor "npm run dev" C-m
Notes

Use `C-m` to send Enter after the command.

Focus a specific window

Choose the window users should see first.

bashANYtmuxselect-window
bash
tmux select-window -t api:editor
Notes

Helpful before attaching to a freshly bootstrapped session.

Attach after setup

Open the session after all windows and panes are ready.

bashANYtmuxattachbootstrap
bash
tmux attach-session -t api
Notes

Creates a polished project startup experience.

Recommended next

No recommendations yet.