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 …
# 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.
12
source shorty.zsh
shorty your_url
And if you are running Ohmyzsh framework, then just make it available as a custom
plugin.
# 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'