Skip to content

Instantly share code, notes, and snippets.

@trentm
Created July 31, 2013 22:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trentm/6126755 to your computer and use it in GitHub Desktop.
Save trentm/6126755 to your computer and use it in GitHub Desktop.
Bash function to use the goo.gl URL shortener on stdin. See <https://developers.google.com/url-shortener/v1/getting_started> TODO: pbcopy it too if that command is available
# echo URL | googl
function googl {
local url=$(cat <&0)
(
set -e pipefail;
echo "{}" \
| json -e "this.longUrl='$url'" \
| curl -sf https://www.googleapis.com/urlshortener/v1/url \
-H 'Content-Type: application/json' -d@- \
| json id
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment