How to copy text to the clipboard when using Wayland?

18

4

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.

mh-cbon

Posted 2017-03-16T21:43:10.977

Reputation: 261

1I'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... – thebunnyrules – 2018-02-22T06:22:01.800

Discussion regarding wayland + clipboard - https://wiki.gnome.org/Initiatives/Wayland/PrimarySelection. According to this ticket it sounds like it's been implemented - https://github.com/swaywm/sway/issues/1012.

– slm – 2018-06-12T02:38:34.090

thanks for the links however that did not help me. maybe i missed something – mh-cbon – 2018-06-12T17:14:32.527

Answers

12

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.

adabru

Posted 2017-03-16T21:43:10.977

Reputation: 236

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 – 2019-05-19T18:56:02.303

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 – 2019-05-20T22:37:47.780

it works perfectly after i installed wayland-devel package. Thanks! – mh-cbon – 2019-05-21T00:11:53.173

4

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.

J. Wang

Posted 2017-03-16T21:43:10.977

Reputation: 49