Skip to content

Instantly share code, notes, and snippets.

@dsc
Created February 12, 2010 19:03
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 dsc/302866 to your computer and use it in GitHub Desktop.
Save dsc/302866 to your computer and use it in GitHub Desktop.
bitly.sh -- shorten URLs without an API key
#!/bin/bash
# @author dsc@less.ly
if test "$1"; then
LONG_URL="$1"
else
read LONG_URL
fi
BITLY="http://bit.ly/?s=&keyword=&url="
function uri () {
python -c "import urllib; print urllib.quote('$1')"
}
# Look for:
# <input id="shortened-url" value="http://bit.ly/bNbWTp" />
curl -s --url "${BITLY}$(uri "$LONG_URL")" | \
sed -nE -e '/id="shortened-url"/ {s/^.*value="([^"]+)".*$/\1/g;p;}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment