Skip to content

Instantly share code, notes, and snippets.

@Rajchowdhury420
Last active November 26, 2020 07:16
Show Gist options
  • Save Rajchowdhury420/7017bb7ebd3274bb12fb38d8e5199cf9 to your computer and use it in GitHub Desktop.
Save Rajchowdhury420/7017bb7ebd3274bb12fb38d8e5199cf9 to your computer and use it in GitHub Desktop.
Url link shortner Bash Script
#!/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=$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`
@Rajchowdhury420
Copy link
Author

Rajchowdhury420 commented Nov 26, 2020

To install this as a standard Linux command, download the gist and rename it "tny". Then, on a shell, do the following:

cd # to the directory where you downloaded it

chmod +x tny
sudo mv tny /usr/bin

Now you can simply do

tny http://some-long-url.com

to shorten URLs from the shell.

As said on the script, you can also have a second parameter to create a custom short URL. Example:

tny http://some-long-url.com shorter

will return

http://tny.im/shorter

And you can use pipes redirection too:

echo http://some-long-url.com | tny

Enjoy!

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