You are not logged in.
I run a two-computer setup. Both systems are running Sway and I would like to set up text-only clipboard sync between them.
So here's where I'm at: By storing a SWAYSOCK reference in /tmp I'm able to interact between the two computers with swaymsg. This has worked perfectly for dpms control using swaymsg over ssh for a while now. Storing WAYLAND_DISPLAY the same way, I'm able to interact with wl-copy and wl-paste over ssh. I'm checking the mimetypes for text/plain to only send text, and checking current clipboard contents before setting them to prevent infinite loops. The problem I'm running into comes with wl-copy over ssh.
The sending side is easy, just this:
#!/bin/bash
# run via wl-paste -w /path/to/clipboard-sync
mime=$(wl-paste --list-types)
valid="text/plain"
if [[ $mime =~ $valid ]]; then
wl-paste | ssh 10.0.0.5 wl-copy-remote
fi
Contents of wl-copy-remote:
#!/bin/bash
display=$(< /tmp/wayland_display)
old=$(WAYLAND_DISPLAY=$display wl-paste)
new=$(cat -)
if [ "$old" == "$new" ]; then
exit 1
else
echo $new | WAYLAND_DISPLAY=$display wl-copy
fi
Locally on either system (or via ssh shell), wl-copy-remote does its thing and just works. When called via
wl-paste | ssh 10.0.0.5 wl-copy-remote
...it does set the clipboard contents properly but doesn't fork off and just hangs, causing future copies to fail.
Is there a way to do this gracefully? Like I could do it the opposite way and ssh into the opposite machine every few seconds to grab the output of wl-paste, but that seems like a horrific way of doing it.
Last edited by Taroven (2024-01-17 13:41:10)
Offline
Didn't find a fix for wl-copy hanging over ssh, but I've worked around the problem by sending the clipboard contents to /tmp on the opposite computer with scp and using inotify to watch the file for changes and trigger wl-copy locally.
Offline
Sorry for reviving a very old thread but this is the first result on my search tool.
The issue is that stderr is not closed before forking. You can fix this by doing a `2>/dev/null` redirection.
echo "$new" | wl-copy 2>/dev/null
Offline