Skip to content

a cross platform minimal "copy to clipboard" command-line tool written in C++

License

Notifications You must be signed in to change notification settings

piratheon/clpbrd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

clpbrd

Tiny cross-platform command-line utility to copy text or file contents to the system clipboard.

Features

  • 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)

Build

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

Usage

  • 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

Platform details

  • Windows: uses Win32 clipboard APIs (CF_UNICODETEXT).
  • macOS: uses pbcopy.
  • Linux/Unix: tries xclip, then xsel, then wl-copy (Wayland).

Notes

  • 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.

Example

  1. Copy a sentence:
clpbrd The quick brown fox
  1. Copy a file by path:
clpbrd notes.txt
  1. Force-file with @:
clpbrd @README.md

License

This project is licensed under the MIT license - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

About

a cross platform minimal "copy to clipboard" command-line tool written in C++

Topics

Resources

License

Stars

Watchers

Forks

Languages