Last active
August 14, 2025 10:43
-
-
Save shiona/06ba20c123f317a371fd9d927c2f935d to your computer and use it in GitHub Desktop.
Show clipboard content in a qr code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/sh | |
| # This version uses feh. Much cleaner. | |
| # Fetch data, I prefer primary, but you can edit these to your liking. | |
| if [ $XDG_SESSION_TYPE = "wayland" ]; then | |
| data="${1:-$(wl-paste -p)}" | |
| elif [ $XDG_SESSION_TYPE = "x11" ]; then | |
| data="${1:-$(xclip -o)}" | |
| fi | |
| # If there's no data, exit | |
| [ -e $data ] && exit 1 | |
| # I like to have some sort of border, so I use convert (from imagemagick) | |
| qrencode -s 5 -o - "$data" | convert -bordercolor black -border 8 png:- png:- | feh -x --class floating - | |
| # Assumes "for_window [class="floating"] floating enable" in the i3 config file | |
| # or "for_window [class="floating"] floating enable" in sway config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/sh | |
| # This version uses sxiv. | |
| # Hard dependencies: | |
| # qrencode | |
| # xclip | |
| # i3 specific stuff requires | |
| # xdotool | |
| # wmctrl | |
| # i3-msg | |
| data=$1 | |
| [[ -z $data ]] && data=$(xclip -o) | |
| # Create temp image and open it "in the background" with sxiv | |
| imagepath=$(mktemp /tmp/qr.XXXX) | |
| imagedata=$(qrencode -s 5 -o $imagepath "$data") | |
| # IF YOU ARE NOT USING i3, uncomment the two lines below and comment everything else below that | |
| # sxiv "$imagepath" | |
| # rm "$imagepath" | |
| # Set the classname (not name as man page suggests) to a unique identifier | |
| sxiv -N qrviewer $imagepath & | |
| ## Wait for the window to open and grab its window ID | |
| winid='' | |
| while : ; do | |
| winid=$(xdotool search --classname qrviewer) | |
| [[ -z "${winid}" ]] || break | |
| done | |
| # Focus the window we found | |
| wmctrl -ia "${winid}" | |
| # Make it float | |
| i3-msg floating enable > /dev/null; | |
| # Move it to the center for good measure | |
| i3-msg move position center > /dev/null; | |
| rm $imagepath |
Author
I finally needed this on wayland myself, so I added you fix. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey!
I didn't notice you had a second version available, but I wanted to make the first version working on both X11 and Wayland (e.g. on Fedora 36).
Tested on Ubuntu 20.04 (X11) and Fedora 36 (Wayland). Feel free to add this snippet to your script! :)