Cmdline URL shortener & expander

terminalMost URL shortener services expose their APIs to use in your projects. I was looking for something similar to use from the cmdline for sharing links. There are some solutions using Google’s goo.gl service which are not working. However, I found the tny.im API to be working. So here’s your cute cmdline URL shortener and expander.

tny()
{
    echo `wget -qO- http://tny.im/yourls-api.php?action=shorturl\&format=simple\&url=$1`
}

untny()
{
    echo `wget -qO- http://tny.im/yourls-api.php?action=expand\&format=simple\&shorturl=$1`
}

Add the above snippet to your ~/.bashrc to use.

Usage

$ tny https://google.com
http://tny.im/120UE
$ untny http://tny.im/120UE
https://google.com

Note that the following also work:

$ tny google.com
$ tny http://google.com
$ tny https://www.google.com

However, http:// is required for untny().

2 thoughts on “Cmdline URL shortener & expander”

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s