Skip to content

Instantly share code, notes, and snippets.

@schtibe
Forked from gbl08ma/tny
Last active May 14, 2024 17:08
Show Gist options
  • Save schtibe/49e133c0a2a66d567bc0 to your computer and use it in GitHub Desktop.
Save schtibe/49e133c0a2a66d567bc0 to your computer and use it in GitHub Desktop.
Unix shell script to shorten URLs with tny.im URL shortener. wget must be installed for this to work.
#!/bin/sh
if [ -t 0 ]; then
if [ -z "$1" ]; then
echo "usage: tny long_url [custom_keyword]"
echo ""
echo "Shorten URLs with tny.im URL shortener"
echo "This script expects a long URL to shorten either as an argument or passed through STDIN."
echo "When using arguments, an optional second argument can be provided to customize the later part of the short URL (keyword)."
exit 1
fi
url=$(python -c "import urllib.parse; print(urllib.parse.quote_plus('$1'))");
else
while read -r line ; do
url=$line
done
fi
echo `wget -q -O - http://tny.im/yourls-api.php?action=shorturl\&format=simple\&url=$url\&keyword=$2`
@schtibe
Copy link
Author

schtibe commented Feb 20, 2023

Hey. What do you mean exactly with "it doesn't work"?

@OrionRandD
Copy link

OrionRandD commented Feb 20, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment