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 paste-buffer -p wraps a paste in bracketed paste codes

Tmux
~/tips/tip-tmux-paste-buffer-bracketed

tmux list-keys -T prefix ]

Pastes a tmux buffer so the shell or editor knows it is pasted text, not typing.

Modern shells and editors can tell typing from pasting, if the paste comes wrapped in two special codes. That is bracketed paste. Ctrl-b ] already does it, but a paste from your own binding or a script does not, unless you add -p.

Look at the default binding and you see the flag:

tmux list-keys -T prefix ]

That prints bind-key -T prefix ] paste-buffer -p. When you write your own paste binding or paste into another pane from a script, copy that -p:

tmux paste-buffer -p -b notes -t work

This pastes the buffer called notes into the session work. When the program in that pane has asked for bracketed paste, tmux puts ESC[200~ before the text and ESC[201~ after it. A shell with bracketed paste on then puts the text on the command line and waits for Enter, even when the text ends with a newline. Editors that support bracketed paste treat the text as one paste too.

You can see it work with cat -v in a pane after printf '\033[?2004h': the paste shows up as ^[[200~echo one^[[201~. Without -p the same paste is plain echo one.

Two more flags help here. -d deletes the buffer after pasting, and -b picks a named buffer instead of the newest one.

The codes only go out when the program asked for them. A program that never asks, or an old shell without bracketed paste, gets a normal paste, and a newline at the end still runs the line. I’d also not count on it with send-keys, which types the text key by key. For anything that would hurt when run by accident, I’d check the buffer first with tmux show-buffer.

Further reading: tmux manual page (OpenBSD), tmux wiki: Clipboard

Going deeper: Guide: tmux in daily use, sessions, popups, plugins and work over SSH

More Tmux tips set -s extended-keys on set -s history-file ~/.tmux_history set -g prefix2 C-a bind S run-shell -b '~/bin/sync-notes.sh' set -g status-justify centre All Tmux tips (133) All topics

Link