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: set -g copy-command sends every tmux copy to your system clipboard

Tmux
~/tips/tip-tmux-copy-command

set -g copy-command 'pbcopy'

Pipes copied text to pbcopy, wl-copy or xclip automatically.

OSC 52 clipboard support doesn’t work in every terminal. A more direct route is to let tmux pipe every copy into the clipboard tool of your system.

set -g copy-command 'pbcopy'

That is for macOS. On Linux, use the tool that matches your desktop:

set -g copy-command 'wl-copy'
set -g copy-command 'xclip -selection clipboard -in'

The first is for Wayland, the second for X11. Since tmux 3.2, the copy commands in copy mode that pipe somewhere use this option when you don’t give them a command of their own. The default Enter key in vi copy mode and mouse drag selection both run copy-pipe-and-cancel without an argument, so after this one line your selections land in the clipboard as well as in a tmux buffer.

If you bound your own keys with an explicit command, like copy-pipe-and-cancel 'pbcopy', those keep working. With the option set I’d drop the argument, so the config works on both systems with one line that changes.

The catch is that the command runs where the tmux server runs. Inside an SSH session, pbcopy on the remote machine fills the remote clipboard, not the one on your laptop. For that case, set-clipboard and a terminal with OSC 52 is the better fit.

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

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link