bugaevc / wl-clipboard

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

[Question] Possibility of notifications #164

Closed octvs closed 1 year ago

octvs commented 1 year ago

Hey there, thanks for the nice tool.

I had the idea to have some notifications when there is something entering the clipboard. Just like in Android, to ensure I've managed to copy something.

I created a ~/.local/bin/wl-copy

#!/bin/sh
/usr/sbin/wl-copy "$@" && notify-send "wl-clipboard" "Copied to clipboard!" -t 500

Although this makes it quite annoying to work with vim which constantly sends a notification. I was wondering if there is a better way to achieve what I want. As far as I can understand there is nothing that makes wl-copy distinguish which app it is called from.

My apologies if I'm populating somewhere that is meant for bug reports with a question.

bugaevc commented 1 year ago

Hi!

As far as I can understand there is nothing that makes wl-copy distinguish which app it is called from.

If you're wrapping wl-copy in a shell script, it should be easy to detect your caller. Perhaps like this:

/usr/sbin/wl-copy "$@"
if [ x$(readlink /proc/$PPID/exe) = x$(which vim) ]; then
    echo Invoked from vim, not notifying
    exit
fi
notify-send "wl-clipboard" "Copied to clipboard!" -t 500

That's just shell scripting, it has nothing to do with wl-clipboard.

But note that if you're doing this by wrapping wl-copy, you're only going to get notified about the copies made by calling your wrapper. For instance if you open any GUI app and Ctrl-C there, it won't shell out to wl-copy, it'll just use the Wayland clipboard directly, so you won't get notified. What you really want is to use wl-paste --watch notify-send "wl-clipboard" "Copied to clipboard!" -t 500. And in that case, yeah, it's unclear how to detect & ignore vim.

My apologies if I'm populating somewhere that is meant for bug reports with a question.

Well, yes, but it's alright, since I haven't enabled GitHub discussions, nor is there a mailing list.

I'm going to close this as it's not a wl-clipboard issue, but please feel free to keep writing / asking further questions here 🙂