wl-copy
Copy text to the Wayland clipboard
TLDR
Copy the text to the clipboard
Pipe the command (ls) output to the clipboard
Copy for only one paste and then clear it
Copy an image
Clear the clipboard
SYNOPSIS
wl-copy [OPTIONS] [TEXT...]
COMMAND | wl-copy [OPTIONS]
PARAMETERS
-p, --primary
Use the primary selection instead of the default clipboard selection.
-s, --selection <name>
Use a specified named selection (e.g., "clipboard", "primary", "secondary").
-f, --fork
Fork the wl-copy process into the background, ensuring the copied data remains available even after the parent process exits.
-o, --once
Exit after the first successful paste operation by another client that consumes the selection.
-c, --clear
Clear the specified selection, removing any existing content.
-n, --no-trim
Do not trim trailing newlines from the input content.
-t, --type <mime-type>
Specify the MIME type of the content being copied (e.g., text/html, image/png). The default is text/plain;charset=utf-8.
-u, --unset
Unset the selection immediately when wl-copy exits, making the content unavailable.
DESCRIPTION
wl-copy is a command-line utility for interacting with the Wayland compositor's clipboard. It allows users to copy text or other data from standard input or command-line arguments directly into the Wayland clipboard buffer. As part of the wl-clipboard project, it provides a crucial bridge for command-line users to integrate with Wayland's modern clipboard mechanisms, which differ significantly from the X11 clipboard system used by tools like xclip or xsel.
wl-copy handles various MIME types, making it versatile for copying not just plain text but also richer data formats. It supports both the standard "clipboard" selection and the "primary" selection (often used for middle-click paste), offering flexibility for different user workflows. Its --fork option is particularly useful for copying data from scripts or processes that terminate, ensuring the copied content remains available. This makes wl-copy an essential tool for scripting and automation in Wayland environments.
CAVEATS
Dependency on Wayland Compositor: wl-copy requires a running Wayland compositor to function. It will not work in X11 environments or if no Wayland compositor is active.
Clipboard Persistence: The availability of copied content is dependent on the compositor and other Wayland clients. For persistence when copying from short-lived processes (like shell commands), the --fork option is crucial, as it keeps wl-copy running in the background to serve the data.
MIME Type Compatibility: While wl-copy can specify MIME types, the ability to paste rich content (beyond plain text) depends on the Wayland compositor and the pasting application's support for those specific MIME types.
INPUT HANDLING
wl-copy can receive input either as command-line arguments (e.g., wl-copy "Hello World") or from standard input (e.g., echo "Hello World" | wl-copy). When arguments are provided, they are concatenated with spaces before being copied.
PERSISTENCE WITH <B>--FORK</B>
When copying data from a script or a command that exits immediately, wl-copy typically needs to run in the background to keep the copied data available for other applications to paste. The --fork option detaches wl-copy from the terminal, allowing it to continue serving the copied content until another application takes ownership of the selection or the Wayland session ends. Without --fork, the copied data might become unavailable as soon as the wl-copy process terminates.
HISTORY
wl-copy emerged as Wayland began to gain traction as a modern display server protocol, aiming to replace the aging X11 system. The need for command-line clipboard interaction in Wayland environments, similar to xclip or xsel for X11, led to the development of the wl-clipboard project. wl-copy is a key component of this project, providing the "copy" functionality. Its development is intertwined with the maturation of the Wayland ecosystem, filling a critical gap for scripting and terminal-based workflows in Wayland desktops.


