This is a small break post from the Hacker School posts I’ve been making to briefly cover shortenize, a little perl script I wrote a while ago to shorten links on STDIN. It will print the original text back out, replacing the long links with short ones. It’s pretty straightforward to use:
echo "my website is http://schwertly.com" | ./shortenize
./shortenize <file_with_long_urls >file_with_short_ones
It also lets you set a threshold, so you can limit the shortening process to URLs over a certain length of characters:
./shortenize -l 80 <file_with_long_urls >file_with_short_ones
This ends up being useful for links that happen to be short already. I made this because of rss2text. I use rss2text and IRC as my RSS reader. rss2text will dump new links to a file, and I have an IRC bot that picks those files up and reads the contents into topic-specific channels. One of my channels is “#tech”, where all of my tech-related links go. Some feeds produce super long URLs, so I use shortenize with a custom length to keep them short. The threshold is great because I can keep small URLs, and hide things like the entries from NPR:
Another feature of shortenize is the ability to add and use new shorteners. It was surprisingly difficult to find a tool that specifically let you throw STDIN at it, and spit it back to STDOUT. It also seemed that most tools hardcoded most of their providers. Many of the options were “You can use bit.ly” or “Choose one of these 5 providers”. Separating out the provider details makes the tool more flexible and the code cleaner.
I was also happy to remember that pastebinit does this with pastebins. They have a directory of files that describe how to interact with the service. shortenize does this as well. There’s a directory named “.shortenizer.d” that contains files that describe a shortner service. The parser isn’t as fully-featured as pastebinit’s is, but that’s mostly a result of not having to switch yet. I’ve written a description for tinyurl.com, and my friend Eric O’Callaghan‘s shortener, gaw.sh.
So far, I’ve posted over 4000 URLs to gaw.sh without any problems. Try it out!