From 556d3bddf30dedeeb8a98522b5cab3ea3eeb732f Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 8 Nov 2022 04:44:01 +0530 Subject: [PATCH] Add wayland support --- mbin.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mbin.sh b/mbin.sh index d3f3fb0..14b52ef 100755 --- a/mbin.sh +++ b/mbin.sh @@ -7,8 +7,16 @@ HASTEBIN=${HASTEBIN:-1} EDITOR=${EDITOR:-vim} URL=$MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents) +function getClipboard() { + if [[ -v WAYLAND_DISPLAY ]]; then + wl-paste + elif [[ -v DISPLAY ]]; then + xclip -selection clipboard -out + fi +} + if [[ $1 == "-c" || $1 == "--clipboard" ]]; then - text=$(xclip -selection clipboard -out) + text=$(getClipboard) op=$(curl -s --data-binary "${text}" -H "Content-Type:text/plain" "$URL") elif [[ -f $1 ]]; then op=$(curl -s --data-binary "@$1" -H "Content-Type:text/plain" "$URL") @@ -26,7 +34,10 @@ if [[ $HASTEBIN == 1 ]]; then else link=$(echo "$op" | cut -f2 -d'/') fi -if [[ -v DISPLAY ]]; then +if [[ -v WAYLAND_DISPLAY ]]; then + echo "${MKR_BIN}${link}" | tee /dev/tty | wl-copy + xdg-open "${MKR_BIN}${link}" +elif [[ -v DISPLAY ]]; then echo "${MKR_BIN}${link}" | tee /dev/tty | xclip -selection clipboard xdg-open "${MKR_BIN}${link}" else