Copy text to your local clipboard over SSH, just like macOS's built-in pbcopy.
echo "hello" | pbcopy
cat file.txt | pbcopy
pbcopy "some text"- Local terminal that supports OSC 52: iTerm2, Alacritty, Kitty, WezTerm
- tmux (optional): version 2.6+, with the following line in
~/.tmux.conf:set -g allow-passthrough on
Download the script and place it in ~/.local/bin/:
curl -o ~/.local/bin/pbcopy https://gist.githubusercontent.com/SmileMachine/d8e9978c50f38173a0bda4fbe55a1783/raw/pbcopy
chmod +x ~/.local/bin/pbcopyMake sure ~/.local/bin is in your PATH. If not, add this to your ~/.bashrc or ~/.zshrc:
export PATH="$HOME/.local/bin:$PATH"- Uses the OSC 52 terminal escape sequence. The sequence travels back through SSH and is interpreted by your local terminal, which writes the content to the clipboard.
- Inside tmux, the sequence is wrapped in a DCS passthrough so tmux forwards it to the outer terminal instead of consuming it.
- Very large inputs may be silently truncated depending on your terminal (~1 MB).