/pbcopy-sh

Cross-platform implementation of pbcopy with no dependencies. Works on local and remote Linux hosts, and tmux sessions

Primary LanguageShell

Cross-platform pbcopy

Cross-platform pure POSIX shell implementation of the macOS utility pbcopy. Pipe text to it to put that text on your system clipboard.

It works almost anywhere shell scripts can run (including local and remote Linux hosts, and tmux sessions), provided your terminal emulator supports the OSC52 escape sequence:

macos $ scp pbcopy linuxserver:
macos $ ssh linuxserver
linux $ chmod +x pbcopy
linux $ echo "foobar" | pbcopy
linux $ exit
macos $ pbpaste
foobar

Terminal emulators that support OSC52 include at least iTerm2 (enable "Applications in terminal may access clipboard" in Preferences) and alacritty.

Installation

Place pbcopy on your $PATH, e.g.

curl https://raw.githubusercontent.com/mikepqr/pbcopy-sh/main/pbcopy -o ~/.local/bin/pbcopy && \
  chmod +x ~/.local/bin/pbcopy

It's effectively a one-liner, but I wrapped it up in a very short script to make distribution and documentation easier.

Limitations

Doesn't work inside neovim's terminal emulator (#3) or containers (#4)

Alternatives

References