2018-11-16 10:12:06 +01:00
|
|
|
#!/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.
|
2021-09-09 17:17:05 +02:00
|
|
|
MKR_BIN=${MKR_BIN:-https://bin.webionite.com/}
|
|
|
|
HASTEBIN=${HASTEBIN:-1}
|
2018-11-16 10:26:36 +01:00
|
|
|
EDITOR=${EDITOR:-vim}
|
2021-09-09 17:17:05 +02:00
|
|
|
URL=$MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents)
|
2018-11-16 10:26:36 +01:00
|
|
|
|
2018-11-16 10:56:30 +01:00
|
|
|
if [[ $1 == "-c" || $1 == "--clipboard" ]]; then
|
2021-09-09 17:17:05 +02:00
|
|
|
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")
|
2018-11-16 10:56:30 +01:00
|
|
|
elif [ -t 0 ]; then
|
2021-09-09 17:17:05 +02:00
|
|
|
tmp_file=$(mktemp)
|
|
|
|
"$EDITOR" "$tmp_file"
|
|
|
|
op=$(curl -s --data-binary "@${tmp_file}" -H "Content-Type:text/plain" "$URL")
|
|
|
|
rm "$tmp_file"
|
2018-11-16 10:26:36 +01:00
|
|
|
else
|
2021-09-09 17:17:05 +02:00
|
|
|
op=$(curl -s --data-binary "@-" -H "Content-Type:text/plain" "$URL")
|
2018-11-16 10:26:36 +01:00
|
|
|
fi
|
2018-11-16 10:12:06 +01:00
|
|
|
|
2019-05-11 12:41:19 +02:00
|
|
|
if [[ $HASTEBIN == 1 ]]; then
|
2021-09-09 17:17:05 +02:00
|
|
|
link=$(echo "$op" | jq -r .key)
|
2019-05-11 12:41:19 +02:00
|
|
|
else
|
2021-09-09 17:17:05 +02:00
|
|
|
link=$(echo "$op" | cut -f2 -d'/')
|
2019-05-11 12:41:19 +02:00
|
|
|
fi
|
2019-05-12 13:17:42 +02:00
|
|
|
if [[ -v DISPLAY ]]; then
|
2021-09-09 17:17:05 +02:00
|
|
|
echo "${MKR_BIN}${link}" | tee /dev/tty | xclip -selection clipboard
|
|
|
|
xdg-open "${MKR_BIN}${link}"
|
2019-05-12 13:17:42 +02:00
|
|
|
else
|
2021-09-09 17:17:05 +02:00
|
|
|
echo "${MKR_BIN}${link}"
|
2019-05-12 13:17:42 +02:00
|
|
|
fi
|