Joshua Cox
•⏳ 4 min read•blog

clip - Universal POSIX Clipboard for Linux, macOS & SSH

clip - Universal POSIX Clipboard for Linux, macOS & SSH

Working across different Unix-like environments often means dealing with a fragmented mess of clipboard utilities: wl-copy / wl-paste on modern Wayland desktops, xclip or xsel on X11, pbcopy / pbpaste on macOS, and clip.exe under WSL. To make matters worse, copying text from a remote headless server over an SSH session or inside tmux usually requires awkward mouse highlighting or brittle X11 forwarding.

clip solves this by providing a unified, POSIX-compliant clipboard tool that works across all of these environments out of the box—with zero dependencies.


What is clip?

clip is a lightweight command-line utility written in clean, standard /bin/sh. It automatically detects your display server, terminal capabilities, and operating system, routing clipboard input and output to the appropriate native backend without requiring manual configuration.

Beyond local graphical desktops, clip features first-class support for OSC 52 ANSI escape sequences (--osc52), allowing you to copy text from remote cloud servers, Docker containers, or tmux multiplexers straight to your local workstation's clipboard over standard SSH connections.

Check out the interactive documentation and terminal simulator at joshuacox.github.io/clip or visit the GitHub repository.


Key Capabilities

  • Automatic Environment Detection:
    • Wayland: Automatically delegates to wl-copy and wl-paste.
    • X11: Prefers xclip, falls back to xsel.
    • macOS: Native integration with pbcopy and pbpaste.
    • Windows / WSL: Hooks into clip.exe or powershell.exe.
    • Remote SSH / Headless Sessions: Leverages OSC 52 terminal escapes to write directly to your local emulator clipboard without network tunnels or display servers.
  • Pipe & File Inputs: Pipe standard input (command | clip) or pass multiple files (clip file1.txt file2.txt) with upfront validation.
  • Paste & Symlink Support: Output clipboard contents to stdout using clip -p or invoke via a convenient paste symlink.
  • Trailing Newline Trimming: Strip trailing newlines with -n or --trim—ideal for copying secrets, passwords, git commit hashes, and URLs.
  • Primary Selection: Target the middle-click primary selection buffer with -s / --primary on X11, Wayland, and supported terminals.
  • Clipboard Clearing: Securely wipe clipboard buffers with clip -c.
  • Pure POSIX Compliance: Written in clean /bin/sh with zero external build requirements or runtimes.
  • Shell Completions: Includes tab-completion definitions for Bash, Zsh, and Fish.

Installation

One-Line Quick Install

Install directly to your system:

curl -sL https://git.io/clipinstall | bash

Installs clip, documentation man pages, and shell completions:

git clone https://github.com/joshuacox/clip.git
cd clip
sudo make install

To also install the handy paste symlink:

sudo make install-paste

Via Nix Flake

Run directly or install with Nix:

# Run immediately without installation
nix run github:joshuacox/clip -- --help

# Install to profile
nix profile install github:joshuacox/clip

Via Homebrew (macOS / Linux)

brew install joshuacox/clip/clip

Usage & Examples

1. Copying from Pipelines

Stream stdout directly into your clipboard:

date -I | clip

2. Copying Without Trailing Newlines

Avoid accidental newlines when copying paths, hashes, or tokens:

pwd | clip -n

3. Copying over Remote SSH (OSC 52)

Copy text from a remote server directly to your local physical machine's clipboard without X11 or Wayland forwarding:

ssh user@remote-box 'cat /etc/os-release' | clip --osc52

Or run clip --osc52 directly inside your remote SSH terminal or tmux session:

cat id_ed25519.pub | clip --osc52

4. Copying Files

Quickly load file contents into the clipboard:

clip ~/.ssh/id_rsa.pub
clip header.txt body.txt footer.txt

5. Pasting Clipboard Contents

Output clipboard contents to stdout or redirect into a file:

clip -p > output.txt

(If you installed the paste symlink, you can simply run paste > output.txt!)

6. Wiping Sensitive Clipboard Data

Clear the clipboard buffer immediately after pasting sensitive credentials:

clip -c

Discussion / Comments

Click “Load Comments” to load the Disqus conversation thread.