Skip to content

Commit ab3f03e

Browse files
committed
🐛 Fix: wayland copy image upload bug
1 parent 7cc047b commit ab3f03e

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

src/utils/clipboard/linux.sh

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
#!/bin/sh
2-
3-
if [ -z "$DISPLAY" ]; then
4-
echo "no support" >&2
5-
exit 1
6-
fi
7-
8-
case "$XDG_SESSION_TYPE" in
9-
wayland)
10-
command -v wl-copy >/dev/null 2>&1 || {
11-
echo >&2 "no wl-clipboard"
12-
exit 1
13-
}
14-
wl-paste > "$1" 2>/dev/null
15-
echo "$1"
16-
;;
17-
x11 | tty)
18-
# require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212)
19-
command -v xclip >/dev/null 2>&1 || {
20-
echo >&2 "no xclip"
21-
exit 1
22-
}
23-
# write image in clipboard to file (see http://unix.stackexchange.com/questions/145131/copy-image-from-clipboard-to-file)
24-
filePath=$(xclip -selection clipboard -o 2>/dev/null | grep ^file:// | cut -c8-)
25-
if [ -z "$filePath" ]; then
26-
if
27-
xclip -selection clipboard -target image/png -o >"$1" 2>/dev/null
28-
then
29-
echo "$1"
30-
else
31-
rm -f "$1"
32-
echo "no image"
33-
fi
2+
if [ "$XDG_SESSION_TYPE" = "x11" ]; then
3+
# require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212)
4+
command -v xclip >/dev/null 2>&1 || { echo >&1 "no xclip"; exit 1; }
5+
# write image in clipboard to file (see http://unix.stackexchange.com/questions/145131/copy-image-from-clipboard-to-file)
6+
filePath=`xclip -selection clipboard -o 2>/dev/null | grep ^file:// | cut -c8-`
7+
if [ ! -n "$filePath" ] ;then
8+
if
9+
xclip -selection clipboard -target image/png -o >/dev/null 2>&1
10+
then
11+
xclip -selection clipboard -target image/png -o >$1 2>/dev/null
12+
echo $1
3413
else
35-
echo "$filePath"
14+
echo "no image"
3615
fi
37-
;;
38-
esac
16+
else
17+
echo $filePath
18+
fi
19+
elif [ "$XDG_SESSION_TYPE" = "wayland" ]; then
20+
command -v wl-paste >/dev/null 2>&1 || { echo >&1 "no wl-clipboard"; exit 1; }
21+
isImage=`wl-paste --list-types | grep image`
22+
if [ -n "$isImage" ]; then
23+
wl-paste --type image/png > $1 2>/dev/null
24+
echo $1
25+
else
26+
echo "no image"
27+
exit 1
28+
fi
29+
fi

0 commit comments

Comments
 (0)