bugaevc / wl-clipboard

Command-line copy/paste utilities for Wayland
GNU General Public License v3.0
1.62k stars 60 forks source link

pasting from a bindsym #74

Closed AdrienLemaire closed 4 years ago

AdrienLemaire commented 4 years ago

Hi, and thanks for making and maintaining wl-clipboard! Really can't leave neovim since it supports wl-clipboard by default.

I've recently switched from i3 to sway, and updated the following script to handle text snippet completion:

#!/usr/bin/env bash

CONFIG=${HOME}/.textexpand/
KEY=$(ls $CONFIG | rofi -sep ' ' -dmenu -p "autocomplete")
cat $CONFIG/$KEY | xsel -ib

[ -z $KEY ] && exit 0;

xdotool key ctrl+shift+v

Here's a working script using wl-copy and ydotool:

#!/usr/bin/env bash

CONFIG=${HOME}/.local/share/textexpand/
KEY=$(ls $CONFIG | bemenu -b -i --nb "#3f3f3f" --nf "#dcdccc" --fn "pango:DejaVu Sans Mono 12")
cat $CONFIG/$KEY | wl-copy

[ -z $KEY ] && exit 0;

ydotool key ctrl+shift+v
#wl-paste 

This is binded in my sway conf as follow

# text snippet auto-completion
bindsym $mod+t exec /home/dori/.local/bin/textexpand

I believe the ydotool dependency to be unnecessary, but I couldn't figure out how to get wl-paste to print the text in my vim pane. I can only see the message printed in journalctl logs as /usr/lib/gdm-wayland-session.

I thought it might be something to do with seats, but a swaymsg -t get_seats only returns seat0, and wl-paste -s seat0 didn't change anything. Using the primary clipboard with wl-copy and wl-paste had no effect as well.

Any idea why wl-paste doesn't work as expected, and what to do to fix it?

bugaevc commented 4 years ago

Thanks for such a detailed ticket! If only others filed their issues with this amount of detail :)

I couldn't figure out how to get wl-paste to print the text in my vim pane.

Any idea why wl-paste doesn't work as expected, and what to do to fix it?

I don't understand why you would actually expect it to output the text into your vim pane. wl-paste outputs the clipboard contents to its stdout (which is the system journal if you start gdm from systemd, sway from gdm and wl-paste from sway). It does not ask the "current" application to paste from clipboard into its focused text field — that is a very different thing and that is roughly the effect ydotool key ctrl+shift+v has.

If you want wl-paste's output to go to vim, you have to find a way to have its stdout connected to vim. This usually means actually running wl-paste from inside vim, not from Sway. But then if you do that, why even bother with the clipboard.

Again, I'm not sure why would you expect this to work any differently, conceptually, than with X11, where you do use xdotool. Maybe you can explain how do you expect this to work?

AdrienLemaire commented 4 years ago

@bugaevc sorry about that, I got confused and made incorrect assumptions. You lovely explained how things should work, thank you very much for taking that time. Really appreciated :heart_eyes:

bugaevc commented 4 years ago

Pro tip: you've got a Useless Use Of Cat there: just wl-copy < $CONFIG/$KEY would work as well :smile: (unless you're relying on being able to paste multiple suggestions at the same time, of course)