Compare commits

..

1 Commits

Author SHA1 Message Date
f903d60922 Refactor the script and change defaults 2021-09-09 20:47:19 +05:30

17
mbin.sh
View File

@@ -3,20 +3,12 @@
# Set MKR_BIN if not set. Export it in your shell rc to use a self hosted # Set MKR_BIN if not set. Export it in your shell rc to use a self hosted
# instance. Include the trailing slash with custom urls. # instance. Include the trailing slash with custom urls.
MKR_BIN=${MKR_BIN:-https://bin.webionite.com/} MKR_BIN=${MKR_BIN:-https://bin.webionite.com/}
HASTEBIN=${HASTEBIN:-1} HASTEBIN=${HASTEBIN:1}
EDITOR=${EDITOR:-vim} EDITOR=${EDITOR:-vim}
URL=$MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents) 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 if [[ $1 == "-c" || $1 == "--clipboard" ]]; then
text=$(getClipboard) text=$(xclip -selection clipboard -out)
op=$(curl -s --data-binary "${text}" -H "Content-Type:text/plain" "$URL") op=$(curl -s --data-binary "${text}" -H "Content-Type:text/plain" "$URL")
elif [[ -f $1 ]]; then elif [[ -f $1 ]]; then
op=$(curl -s --data-binary "@$1" -H "Content-Type:text/plain" "$URL") op=$(curl -s --data-binary "@$1" -H "Content-Type:text/plain" "$URL")
@@ -34,10 +26,7 @@ if [[ $HASTEBIN == 1 ]]; then
else else
link=$(echo "$op" | cut -f2 -d'/') link=$(echo "$op" | cut -f2 -d'/')
fi fi
if [[ -v WAYLAND_DISPLAY ]]; then if [[ -v 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 echo "${MKR_BIN}${link}" | tee /dev/tty | xclip -selection clipboard
xdg-open "${MKR_BIN}${link}" xdg-open "${MKR_BIN}${link}"
else else