Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Clipboard history truncates when copying image from browser #3

Open
shumvgolove opened this issue Jan 21, 2025 · 7 comments
Open

Clipboard history truncates when copying image from browser #3

shumvgolove opened this issue Jan 21, 2025 · 7 comments

Comments

@shumvgolove
Copy link

Software

  • rustyclip: 99f8a93
  • wl-clipboard: 2.2.1
  • Firefox: 134.0.1

Steps to reproduce

  1. Execute the following:

    wl-paste -t image --watch rustyclip store &\
    wl-paste -t text --watch rustyclip store
  2. Copy text from the Firefox. For example, the commands above.

  3. Show clipboard:

    ❯ rustyclip list
    1: ❯ rustyclip list1: wl-paste -t image --watch rustyclip store &\    wl-paste -t text --watch rustyc
    2: wl-paste -t image --watch rustyclip store &\    wl-paste -t text --watch rustyclip store
  4. Copy image from the Firefox. For example, my Github profile image.

  5. Observe that clipboard history was truncated:

    ❯ rustyclip list
    1: [[binary data 9.20 KB png 64x64]]

Also, sometimes when copying the image, another entry shows up with HTML content:

❯ rustyclip list
1: [[binary data 9.20 KB png 64x64]]
2: <meta http-equiv="content-type" content="text/html; charset=utf-8"><img data-component="Avatar" class
@Zai-Kun
Copy link
Owner

Zai-Kun commented Jan 21, 2025

That is the expected behavior. The rustyclip list just shows the preview of all stored clipboard items. To get the whole thing, you must use: rustyclip get {index} (The index is the numbering you get when you do rustyclip list.)

Let's say, we I currently have this in my clipboard:
1: [[binary data 9.20 KB png 64x64]]
2: some text 1122
3: another random text 1122

and i wanna get the first image. To do that, i will do: rustyclip get 1. This will return two things:

  1. Path to a file that holds the full stored clipboard
  2. The mime type of the file

Example:

/home/zai/.cache/rustyclip/clipboard_data/1372768005954542831
image/png

Then, you can do something like: wl-copy -t "{MIME_TYPE_HERE}" < "{FILE_PATH_HERE}". This will copy the full clipboard history into your clipboard.

Here is an example script that does all of that for you:

#!/bin/bash

RUSTYCLIP=/path/to/rustyclip
PICKER=fuzzel
WLCOPY=wl-copy
NOTIFY_SEND=notify-send

# List clipboard entries and select one using a picker (fuzzel in this example)
output=$($RUSTYCLIP list | $PICKER -d| $RUSTYCLIP get)

# Extract the file path and MIME type from the output
file_path=$(echo "$output" | head -n 1)
mime_type=$(echo "$output" | tail -n 1)

# Check if the file exists and MIME type is non-empty
if [[ -f "$file_path" && -n "$mime_type" ]]; then
    # Copy the file content to the clipboard with the specified MIME type
    $WLCOPY -t "$mime_type" < "$file_path"
    
    # Notify the user
    $NOTIFY_SEND "Copied to clipboard" -t 500
fi

Note: Replace the RUSTYCLIP=/path/to/rustyclip with the actal path of where rusty clip resides, and replace PICKER=fuzzel with the picker of your choosing (bemenu, fuzzel, etc).

@Zai-Kun
Copy link
Owner

Zai-Kun commented Jan 21, 2025

As for the issue with the HTML entry, you can get rid of it by explicitly telling wl-paste what to watch for:

wl-paste -t text/plain --watch /path/to/rustclip store
wl-paste -t image --watch /path/to/rustclip store

This will watch for images and plain text.

@Zai-Kun
Copy link
Owner

Zai-Kun commented Jan 21, 2025

Please et me know if you have questions or issues.

@shumvgolove
Copy link
Author

That is the expected behavior.

Not sure if I understand this correctly, but shouldn't my previous entries stay the same, while copied image show at the top of the index?

Like:

❯ rustyclip list
1: [[binary data 9.20 KB png 64x64]]
2: ❯ rustyclip list1: wl-paste -t image --watch rustyclip store &\    wl-paste -t text --watch rustyc
3: wl-paste -t image --watch rustyclip store &\    wl-paste -t text --watch rustyclip store

Instead of this it seems like copying image deletes all previous history (like in Steps to reproduce):

❯ rustyclip list
1: [[binary data 9.20 KB png 64x64]]

Here is an example script that does all of that for you:

Yeah, I'm using this script from the README (although adapted to be POSIX-compatible). Thank you for this awesome project.

As for the issue with the HTML entry, you can get rid of it by explicitly telling wl-paste what to watch for:

wl-paste -t text/plain --watch /path/to/rustclip store
wl-paste -t image --watch /path/to/rustclip store

This will watch for images and plain text.

This was in my config before I noticed that emojis preserve as unicode codepoints instead of actual emojis. Is there any way to preserve those?

@Zai-Kun
Copy link
Owner

Zai-Kun commented Jan 21, 2025

After doing some testing, I was able to recreate the emoji issue. Instead of watching for mime type text/plain, watch for "text/plain;charset=utf-8". That fixed the issue for me.
Example: wl-paste -t "text/plain;charset=utf-8" --watch /path/to/rusty/clip. That should solve the emoji issue.

As for the clipboard items clearing after copying images from firefox, I had the same issue and I will figure out what is causing it. For now, just make sure you use the "text/plain;charset=utf-8" mime type instead. It solved the issue with emojis and the clipboard being cleared after copying images.
Complete set:

wl-paste -t "text/plain;charset=utf-8" --watch /path/to/rustclip store
wl-paste -t image --watch /path/to/rustclip store

Let me know if it fixed the issue or not.

@shumvgolove
Copy link
Author

Instead of watching for mime type text/plain, watch for "text/plain;charset=utf-8". That fixed the issue for me.

Yep, that fixes it. Many thanks!

On a related note, with these commands in my configuration..

wl-paste -t 'text/plain;charset=utf-8' --watch /usr/local/bin/rustclip store
wl-paste -t image --watch /usr/local/bin/rustclip store

..I cannot reproduce the issue with erasing history when copying the image 🤔

@Zai-Kun
Copy link
Owner

Zai-Kun commented Jan 21, 2025

..I cannot reproduce the issue with erasing history when copying the image 🤔

Yeah, same here. I will have to do some more debugging to figure out why it was fixed (when using the new config) and what was causing it before. Thanks for reporting the issues!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants