Hight throughput procrastination

Decreasing signal to noise ratio

Url Shortner Custom Plugin for Oh-my-zsh

| Comments

I was looking to have a command line for shortning urls, particularly to tag along with my favourite twitter client earthquake. There are bunch of services and i saw one that uses google url shortner. However, it didn’t work as google api requires an API key. So, after getting an API key, here is the command line …

‘url shortner’ (shorty.zsh) download
1
2
3
4
5
6
7
# Add your own custom plugins in the custom/plugins directory. Plugins placed
# here will override ones with the same name in the main plugins directory.
shorty () {
  curl -s https://www.googleapis.com/urlshortener/v1/url\?key\=API_KEY \
     -H 'Content-Type: application/json' \ 
     -d '{"longUrl": "'"$1"'"}' | egrep -o 'http://goo.gl/[^"]*'
}

Now save this in a .bashrc/.zshrc or source it from a separate file to invoke it as a command.

1
2
source shorty.zsh
shorty your_url

And if you are running Ohmyzsh framework, then just make it available as a custom plugin.

1
2
3
cd ~/.oh-my-zsh/custom
mkdir -p plugins/shorty && cd plugins/shorty
cat shorty.zsh > shorty.plugin.zsh

Now activate the plugin in in your ~/.zshrc

activate plugin
1
2
3
4
5
6
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(git rvm cpanm shorty)

$_> source ~/.zshrc
$_> shorty 'url'