-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqrencode_clipboard
More file actions
executable file
·40 lines (33 loc) · 1022 Bytes
/
qrencode_clipboard
File metadata and controls
executable file
·40 lines (33 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# Assign a global hotkey to run this script.
die() {
echo "$*" >&2
[ -t 2 ] || notify-send "$(basename "$0")" "$1" --icon=dialog-error
exit 1
}
notify() {
local text
text=$(echo "$1" | head -c420 | head -n10 | iconv -f utf-8 -t utf-8 -c) # truncate text for notification
if [ "${#text}" -lt "$len" ]; then
text="${text} ..."
fi
notify-send -- "QR Code - Clipboard Content" "$text"
}
read_wayland() {
wl-paste -n
}
read_xorg() {
xclip -selection clipboard -o
}
if [ -n "$WAYLAND_DISPLAY" ]; then
content=$(read_wayland) || die 'Failed to read Wayland clipboard'
elif [ -n "$DISPLAY" ]; then
content=$(read_xorg) || die 'Failed to read Xorg clipboard'
else
die "Neither $$DISPLAY nor $$WAYLAND_DISPLAY is set"
fi
len=${#content}
[ "$len" -le 0 ] && die 'Clipboard is empty'
[ "$len" -gt 2951 ] && die 'Clipboard content is too long'
notify "$content"
echo -n "$content" | qrencode -l L -s 6 -t png -o - | feh - || die 'Failed to create QR Code'