Tiny cross-platform command-line utility to copy text or file contents to the system clipboard.
- Copy literal text: clpbrd Hello world
- Copy a file by path: clpbrd path/to/file.txt
- Explicit file prefix with @: clpbrd @path/to/file.txt
- Works on Windows, macOS, and Unix/Linux (tries xclip, xsel, then wl-copy)
Requires a C++ compiler (g++, clang, MSVC). Example:
- Linux / macOS:
g++ -std=c++11 -O2 -o clpbrd clpbrd.cpp
- Windows (MSVC):
cl /EHsc /O2 clpbrd.cpp
- Copy literal text:
clpbrd <text...>
# Example:
clpbrd Hello world
- Copy a single file (automatic if argument is an existing file):
clpbrd path/to/file.txt
- Force file interpretation using @ prefix:
clpbrd @path/to/file.txt
- If you prefer an explicit file-only invocation, you can call:
clpbrd ./file.txt
Exit codes:
- 0 — success (or nothing copied if input empty)
- 2 — invalid usage (no arguments)
- 3 — file read error
- 4 — clipboard copy failure
- Windows: uses Win32 clipboard APIs (CF_UNICODETEXT).
- macOS: uses pbcopy.
- Linux/Unix: tries xclip, then xsel, then wl-copy (Wayland).
- If clipboard utilities (xclip/xsel/wl-copy/pbcopy) are not installed on Unix/macOS, copying will fail with an error message.
- The program reads files in binary mode and forwards contents unchanged to the clipboard.
- Copy a sentence:
clpbrd The quick brown fox
- Copy a file by path:
clpbrd notes.txt
- Force-file with @:
clpbrd @README.md
This project is licensed under the MIT license - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.