Sometimes it's not easy to get things from a terminal to your system clipboard. If you're connected locally, it has to be a special tool which handles this (like wl-clipboard
under Wayland) or something other when connected remotely.
This is a Shell executable which ultimately solves the problem by always reaching your local system clipboard:
#!/bin/bash
printf "\e]52;c;$(base64 -w0)\a"
On a remote machine, create and make this script executable (chmod +x oscopy
) and ensure it's in the PATH.
Usage:
# Works either locally or connected via SSH.
echo hola | oscopy
# "hola" can be pasted now.
cat bonjour.txt | oscopy
# Contents of "bonjour.txt" can be pasted now.
Tested on a remote Arch Linux, Ubuntu and a local MacBook with another Arch Linux. Data travels from one distribution to another via SSH with no problems.
This script basically involves the OSC 52 escape sequence, a modern thing which makes your terminal treat all the text it receives as something to put into the clipboard.
Remote machine sends this OSC 52 sequence, if text is displayed directly on a terminal launched on a remote machine, it's this terminal which treats it and fills the clipboard out on the remote machine.
If you were connected via SSH to this machine, the 52 sequence travels right to your machine and is treated on your local machine.
It's simple. But could be not yet implemented on old terminal emulators.