brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tmux new -d -x 200 -y 50 gives a detached session a real size

Tmux
~/tips/tip-tmux-detached-session-size

tmux new -d -s report -x 200 -y 50 'top'

Starts a background tmux session wider than 80 columns, so scripts don't get wrapped output.

A session started with -d has no terminal attached, so tmux has to pick a size for it. That size is 80 by 24, which is tiny for anything that prints wide tables or long log lines.

Programs in that session think the screen is 80 columns wide. They wrap or cut their output to fit, and that is what you get back when you read the pane with capture-pane later. The -x and -y flags of new-session give the detached session a proper size:

tmux new -d -s report -x 200 -y 50 'top'

Check it with:

tmux display -p -t report '#{window_width}x#{window_height}'

That prints 200x50. Without the two flags you get 80x24.

The 80 by 24 comes from the option default-size, and tmux sets that option for the session when you pass -x or -y. You can also change it globally in ~/.tmux.conf, so every detached session starts bigger:

set -g default-size 200x50

I’d use this for any session a script starts and reads back later, and for a session you prepare before you attach to it.

The size only holds while nobody is attached. Attach to the session and the window takes the size of your terminal, because window-size is latest by default. After you detach it keeps that size, not the 200 by 50 you asked for, so a script that depends on the width should not run after someone has looked at the session.

Further reading: tmux manual page (OpenBSD), tmux wiki: Advanced Use

More Tmux tips tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ tmux new -s scratch \; set destroy-unattached on All Tmux tips (125) All topics

Link