Created
February 12, 2010 19:03
-
-
Save dsc/302866 to your computer and use it in GitHub Desktop.
bitly.sh -- shorten URLs without an API key
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
#!/bin/bash | |
# @author [email protected] | |
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