Skip to content

Instantly share code, notes, and snippets.

@jcanfield
Forked from wafflesnatcha/goo.gl.sh
Created June 11, 2017 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcanfield/ae0016933d82431303ae9b4cd7ab9d69 to your computer and use it in GitHub Desktop.
Save jcanfield/ae0016933d82431303ae9b4cd7ab9d69 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