Last active
March 13, 2018 04:49
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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