Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

remote-pbcopy

Copy remote command output to your local Mac clipboard — over SSH, no extra tools required.

The problem: When you're SSH'd into a remote machine and working inside a multiplexer like tmux or Zellij, copying output between panes — and then sharing it with an AI agent or another tool — means endless manual select → copy → paste cycles. There's no pbcopy on Linux, and xclip/xsel don't work over SSH.

The solution: A tiny shell script that wraps output in an OSC 52 terminal escape sequence. Your local terminal (iTerm2) sees the sequence and writes the content directly to your Mac clipboard — transparently, over the existing SSH connection.


中文文档


How it works

remote command output
  → base64 encoded
  → wrapped in \033]52;c;<data>\a
  → sent through SSH to your terminal
  → iTerm2 writes it to macOS clipboard

No sockets, no ports, no daemons. Just a terminal escape sequence.

Prerequisites

On your Mac (one-time):

iTerm2 → Settings → General → Selection → enable "Applications in terminal may access clipboard"

Multiplexer passthrough:

  • Zellij: works out of the box
  • tmux: add set -s set-clipboard on to ~/.tmux.conf

Install

Run this on your remote Linux machine:

bash <(curl -fsSL https://raw.githubusercontent.com/Meteors27/remote-pbcopy/main/install.sh)

Then reload your shell:

source ~/.bashrc   # or source ~/.zshrc

Manual install

# 1. Install pbcopy
sudo tee /usr/local/bin/pbcopy << 'EOF'
#!/bin/bash
printf "\033]52;c;$(cat | base64 | tr -d '\n')\a"
EOF
sudo chmod +x /usr/local/bin/pbcopy

# 2. Add cpy alias (shows output AND copies)
echo "alias cpy='tee >(pbcopy)'" >> ~/.bashrc
source ~/.bashrc

Usage

# Copy to clipboard (silent)
echo "hello" | pbcopy
cat file.txt | pbcopy
git log --oneline | head -20 | pbcopy

# Show output AND copy simultaneously
ls -la | cpy
grep -r "TODO" . | cpy

Verify

bash <(curl -fsSL https://raw.githubusercontent.com/Meteors27/remote-pbcopy/main/install.sh) --verify

Limitations

  • Requires iTerm2 on the Mac side (or another terminal with OSC 52 support, e.g. WezTerm, Kitty)
  • Large payloads (>100 KB) may be truncated by some terminals
  • Multi-hop SSH (jump hosts): OSC 52 only propagates through the terminal you're directly connected to

License

MIT

About

Copy remote command output to your local Mac clipboard over SSH — via OSC 52 terminal escape sequences

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages