Feature: add wayland support for linux

This commit is contained in:
zhullyb 2022-03-14 20:41:34 +08:00 committed by PiEgg
parent 6bcda9ba28
commit f1c8507927

View File

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
# require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212) if [ "$XDG_SESSION_TYPE" = "x11" ]; then
command -v xclip >/dev/null 2>&1 || { echo >&1 "no xclip"; exit 1; } # require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212)
command -v xclip >/dev/null 2>&1 || { echo >&1 "no xclip"; exit 1; }
# write image in clipboard to file (see http://unix.stackexchange.com/questions/145131/copy-image-from-clipboard-to-file) # write image in clipboard to file (see http://unix.stackexchange.com/questions/145131/copy-image-from-clipboard-to-file)
filePath=`xclip -selection clipboard -o 2>/dev/null | grep ^file:// | cut -c8-` filePath=`xclip -selection clipboard -o 2>/dev/null | grep ^file:// | cut -c8-`
if [ ! -n "$filePath" ] ;then if [ ! -n "$filePath" ] ;then
if if
xclip -selection clipboard -target image/png -o >/dev/null 2>&1 xclip -selection clipboard -target image/png -o >/dev/null 2>&1
then then
@ -13,6 +13,22 @@ if [ ! -n "$filePath" ] ;then
else else
echo "no image" echo "no image"
fi fi
else else
echo $filePath echo $filePath
fi
elif [ "$XDG_SESSION_TYPE" = "wayland" ]; then
command -v wl-copy >/dev/null 2>&1 || { echo >&1 "no wl-clipboard"; exit 1; }
filePath=`wl-copy -o 2>/dev/null | grep ^file:// | cut -c8-`
if [ ! -n "$filePath" ] ;then
if
wl-copy -t image/png -o >/dev/null 2>&1
then
wl-copy -t image/png image/png -o >$1 2>/dev/null
echo $1
else
echo "no image"
fi
else
echo $filePath
fi
fi fi