2017-05-19 15:51:00 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
YADUS_URL="https://tiny.tobast.fr/+submit"
|
|
|
|
|
|
|
|
if [ "$#" -lt "1" ]; then
|
|
|
|
url=$(/usr/bin/dmenu -p "Url to shorten" < /dev/null) || exit 1
|
|
|
|
else
|
2017-06-15 12:10:27 +02:00
|
|
|
url="$1"
|
2017-05-19 15:51:00 +02:00
|
|
|
fi
|
|
|
|
|
2017-06-15 12:10:27 +02:00
|
|
|
curl_out=$(/usr/bin/curl -sw '\n%{http_code}' -X POST \
|
|
|
|
--data-urlencode url="$url" "$YADUS_URL")
|
2017-05-19 15:51:00 +02:00
|
|
|
http_code=$(echo -e "$curl_out" | tail -n 1)
|
|
|
|
http_body=$(echo -e "$curl_out" | head -n -1)
|
|
|
|
|
|
|
|
if [ "$http_code" -ne "200" ] ; then
|
|
|
|
# error
|
|
|
|
echo -n "" | /usr/bin/xclip -selection clipboard
|
|
|
|
/usr/bin/notify-send -t 2000 "Yadus error" \
|
|
|
|
"Could not shorten URL ($http_code): $http_body."
|
|
|
|
else
|
|
|
|
echo -n "$http_body" | /usr/bin/xclip -selection clipboard
|
|
|
|
fi
|