Most 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().