You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

4 years ago
#!/usr/bin/env bash
# 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.
MKR_BIN=${MKR_BIN:-https://bin.webionite.com/}
HASTEBIN=${HASTEBIN:-1}
EDITOR=${EDITOR:-vim}
URL=$MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents)
if [[ $1 == "-c" || $1 == "--clipboard" ]]; then
text=$(xclip -selection clipboard -out)
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")
elif [ -t 0 ]; then
tmp_file=$(mktemp)
"$EDITOR" "$tmp_file"
op=$(curl -s --data-binary "@${tmp_file}" -H "Content-Type:text/plain" "$URL")
rm "$tmp_file"
else
op=$(curl -s --data-binary "@-" -H "Content-Type:text/plain" "$URL")
fi
4 years ago
if [[ $HASTEBIN == 1 ]]; then
link=$(echo "$op" | jq -r .key)
else
link=$(echo "$op" | cut -f2 -d'/')
fi
if [[ -v DISPLAY ]]; then
echo "${MKR_BIN}${link}" | tee /dev/tty | xclip -selection clipboard
xdg-open "${MKR_BIN}${link}"
else
echo "${MKR_BIN}${link}"
fi