You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

url-unshorten 1008B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. # From https://github.com/benjaminoakes/utilities
  3. set -o errexit
  4. function show-usage {
  5. cat <<EOF
  6. Usage: $0 [--help] [url | [[-f | --file] path]]
  7. Map shortened URLs to their expanded versions.
  8. --help Show this help text.
  9. url A single URL to resolve.
  10. path File containing URLs to resolve, one per line.
  11. Example:
  12. $ $0 http://t.co/asdf
  13. http://t.co/foo => http://example.com/
  14. $ cat file.txt
  15. http://t.co/foo
  16. http://t.co/bar
  17. $ $0 --file file.txt
  18. http://t.co/foo => http://example.com/baz
  19. http://t.co/bar => http://example.com/qux
  20. EOF
  21. exit -1
  22. }
  23. function resolve {
  24. url="$1"
  25. echo -n "$url => "
  26. curl --verbose "$url" 2>&1 |
  27. grep 'Location: ' |
  28. sed 's/< Location: //'
  29. }
  30. # TODO: also accept URL as parameter so it doesn't have to be in a file
  31. if [ "$1" == '--help' -o "$1" == '' ]; then
  32. show-usage
  33. fi
  34. if [ "$1" == '-f' -o "$1" == '--file' ]; then
  35. for url in $(cat $2); do
  36. resolve "$url"
  37. done
  38. else
  39. resolve "$1"
  40. fi