Skip to content

Commit 28905f2

Browse files
authored
✨ Feature: add wayland support for linux (#119)
1 parent 1e6373e commit 28905f2

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

src/utils/clipboard/linux.sh

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
#!/bin/sh
2-
# require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212)
3-
command -v xclip >/dev/null 2>&1 || { echo >&1 "no xclip"; exit 1; }
4-
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
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
13+
else
14+
echo "no image"
15+
fi
1316
else
14-
echo "no image"
17+
echo $filePath
18+
fi
19+
elif [ "$XDG_SESSION_TYPE" = "wayland" ]; then
20+
command -v wl-copy >/dev/null 2>&1 || { echo >&1 "no wl-clipboard"; exit 1; }
21+
filePath=`wl-copy -o 2>/dev/null | grep ^file:// | cut -c8-`
22+
if [ ! -n "$filePath" ] ;then
23+
if
24+
wl-copy -t image/png -o >/dev/null 2>&1
25+
then
26+
wl-copy -t image/png image/png -o >$1 2>/dev/null
27+
echo $1
28+
else
29+
echo "no image"
30+
fi
31+
else
32+
echo $filePath
1533
fi
16-
else
17-
echo $filePath
1834
fi

src/utils/getClipboardImage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ const getClipboardImage = async (ctx: IPicGo): Promise<IClipboardImage> => {
9393

9494
execution.stdout.on('data', (data: Buffer) => {
9595
if (platform === 'linux') {
96-
if (data.toString().trim() === 'no xclip') {
96+
if (data.toString().trim() === 'no xclip or wl-clipboard') {
9797
ctx.emit(IBuildInEvent.NOTIFICATION, {
98-
title: 'xclip not found',
99-
body: 'Please install xclip before run picgo'
98+
title: 'xclip or wl-clipboard not found',
99+
body: 'Please install xclip(for x11) or wl-clipboard(for wayland) before run picgo'
100100
})
101-
return reject(new Error('Please install xclip before run picgo'))
101+
return reject(new Error('Please install xclip(for x11) or wl-clipboard(for wayland) before run picgo'))
102102
}
103103
}
104104
const imgPath = data.toString().trim()

0 commit comments

Comments
 (0)