Skip to content

Instantly share code, notes, and snippets.

@OkashiOdayakana
Last active December 16, 2016 21:33
Show Gist options
  • Save OkashiOdayakana/8ad6e3deac47cf3e74bbf0ca5849092c to your computer and use it in GitHub Desktop.
Save OkashiOdayakana/8ad6e3deac47cf3e74bbf0ca5849092c to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z "$key" ]; then
notify-send owoshorten "Please enter your key."
echo "Please enter your key."
read key
fi
notify-send owoshorten "Please enter the URL you wish to shorten."
echo "Please enter the URL you wish to shorten."
read url
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ $url =~ $regex ]]
then
result=$(curl "https://api.whats-th.is/shorten/polr?action=shorten&key=$key&url=$url")
echo $result
if grep -q "https://" <<< "${result}"; then
echo $result | xclip -i -sel c -f |xclip -i -sel p
notify-send owoshorten "Copied the link to the keyboard."
else
notify-send owoshorten "Shortening failed!"
fi
else
notify-send owoshorten "Link is not valid!"
echo "Link is not valid!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment