Skip to content

Instantly share code, notes, and snippets.

@wafflesnatcha
Last active March 13, 2018 04:49
Show Gist options
  • Save wafflesnatcha/3694648 to your computer and use it in GitHub Desktop.
Save wafflesnatcha/3694648 to your computer and use it in GitHub Desktop.
Bash: goo.gl # Shorten a URL using the Google URL Shortener service (http://goo.gl).
#!/usr/bin/env bash
# Usage: goo.gl [URL]
#
# Shorten a URL using the Google URL Shortener service (http://goo.gl).
goo.gl() {
[[ ! $1 ]] && { echo -e "Usage: goo.gl [URL]\n\nShorten a URL using the Google URL Shortener service (http://goo.gl)."; return; }
curl -qsSL -m10 --connect-timeout 10 \
'https://www.googleapis.com/urlshortener/v1/url' \
-H 'Content-Type: application/json' \
-d '{"longUrl":"'${1//\"/\\\"}'"}' |
perl -ne 'if(m/^\s*"id":\s*"(.*)",?$/i) { print $1 }'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment