Google URL shortener script


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. # Google url shortener bash script
  3. # For information about the app:
  4. # http://ggl-shortener.appspot.com/instructions/
  5.  
  6. app='http://ggl-shortener.appspot.com/?url='
  7. url="$1"
  8. protocol=`echo "$1" | sed -e "/^http:\/\//g"`
  9.  
  10. if [ -z "$1" ]; then
  11. echo -e "you need to pass the url through an argument";
  12. echo -e "e.g. `basename $0` http://url";
  13. else
  14. if [ ! "$protocol" ]; then
  15. curl -s "$app$url" | sed -e 's/{"short_url":"//' -e 's/"}/\n/g'
  16. else
  17. repl=`echo "$1" | sed -e 's/^/http:\/\//g'`
  18. curl -s "$app$repl" | sed -e 's/{"short_url":"//' -e 's/{"error_message":"Bad request/error: bad request/' -e 's/"}/\n/g'
  19. fi;
  20. fi

URL: http://gist.github.com/346451

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.