Skip to content

Instantly share code, notes, and snippets.

@jcanfield
Forked from trentm/googl.sh
Created June 11, 2017 07:33
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/ff4f084c9104ff281988d8f519421bce to your computer and use it in GitHub Desktop.
Save jcanfield/ff4f084c9104ff281988d8f519421bce 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