40

Is there a Wayland cli utility that copies text to clipboard?

I want to be able to do something like this:

echo "some" > clipboard

Something equivalent to xclip.

3
  • 2
    I'd be really interested to see the answer to this question too. From my usage of gnome-wayland, it seems to have many restrictions on clipboard access. For example, if you copy something in program A and you close it, the clipboard will automatically get flushed. There is no restriction on copy to clipboard for xclip but it seems pasting will only work if you've copied something while in terminal but not anywhere else. on the other hand, ctrl-v/shift-ctrl-v has no restriction as long as original app is opened... Feb 22, 2018 at 6:22
  • Discussion regarding wayland + clipboard - wiki.gnome.org/Initiatives/Wayland/PrimarySelection. According to this ticket it sounds like it's been implemented - github.com/swaywm/sway/issues/1012.
    – slm
    Jun 12, 2018 at 2:38
  • thanks for the links however that did not help me. maybe i missed something
    – mh-cbon
    Jun 12, 2018 at 17:14

3 Answers 3

46

bugaevc's wl-clipboard are copy/paste utilities for Wayland:

This project implements two little Wayland clipboard utilities, wl-copy and wl-paste, that let you easily copy data between the clipboard and Unix pipes, sockets, files and so on.

Usage is as simple as:

# copy a simple text message
$ wl-copy Hello world!

# copy the list of files in Downloads
$ ls ~/Downloads | wl-copy

# copy an image file
$ wl-copy < ~/Pictures/photo.png

# paste to a file
$ wl-paste > clipboard.txt

# grep each pasted word in file source.c
$ for word in $(wl-paste); do grep $word source.c; done

# copy the previous command
$ wl-copy "!!"

# replace the current selection with the list of types it's offered in
$ wl-paste --list-types | wl-copy

Although wl-copy and wl-paste are particularly optimized for plain text and other textual content formats, they fully support content of arbitrary MIME types. wl-copy automatically infers the type of the copied content by running xdg-mime(1) on it. wl-paste tries its best to pick a type to paste based on the list of offered MIME types and the extension of the file it's pasting into. If you're not satisfied with the type they pick or don't want to rely on this implicit type inference, you can explicitly specify the type to use with the --type option.

For all common linux-distributions the package-name is wl-clipboard, so use the command that suits yours (if not already installed):

sudo apt install wl-clipboard  # Debian
sudo dnf install wl-clipboard  # Fedora
sudo pacman -S wl-clipboard    # Arch linux
3
  • looks really cool! but i met with src/meson.build:1:0: ERROR: Dependency "wayland-client" not found, tried pkgconfig and cmake during install. I m sure its a stupid mistake from me. is it ? I have run sudo dnf i meson -y prior to the build attempt.
    – mh-cbon
    May 19, 2019 at 18:56
  • 1
    @mh-cbon On its github page it says: The only mandatory dependency is the wayland-client library (try package named wayland-devel or libwayland-dev). Maybe installing one of those mentioned packages helps? Alternatively, maybe the package can be found in the official package repositories.
    – adabru
    May 20, 2019 at 22:37
  • it works perfectly after i installed wayland-devel package. Thanks!
    – mh-cbon
    May 21, 2019 at 0:11
7

wclip is a clipboard tool for Wayland that is very similar to xclip.

Usage is as follows:

$ wclip i < my_text_file

$ wclip o contents of my text file $

Disclaimer: I am the author.

1
  • 1
    As of Nov 2020, it seems the last commit was nearly 2 years ago. Is the project still alive? Nov 23, 2020 at 13:01
0

I've just 'converted' to a Wayland UX, under Plasma (KDE) and so far most things are as usual. The things important for my workflow have highlighted one or two underlying dependencies on X.Org.

Fortunately, I can use CopyQ as my Clipboard manager of choice. CopyQ appears to be a very friendly Wayland supporter; so far, so good.

For CLI copy and paste I now use the following as bash alias commands:

clip ... Capture the current selection.

alias cliq='copyq selection'
alias clip='cliq; echo'

paste ... Emit current clipboard contents.

alias paste='copyq read '

CopyQ can be installed on flathub from:

I've used CopyQ as soon as I installed my first Linux desktop.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .