Skip to content

Instantly share code, notes, and snippets.

@mAu888
Last active August 29, 2015 14:26
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 mAu888/b6b6ff8b1b4186213725 to your computer and use it in GitHub Desktop.
Save mAu888/b6b6ff8b1b4186213725 to your computer and use it in GitHub Desktop.
Resolve (short) URLs
# Put this into your `~/.bashrc` and `source ~/.bashrc`
function expandurl {
# -s Only output
# -I HEAD request
# -L Follow redirects. Combined with -I will print headers from all intermediate redirects
REDIRECTS=$(curl -sIL $1 | grep ^Location);
if [[ -z $REDIRECTS ]]; then
echo "Location: ${1}";
else
echo "$REDIRECTS";
fi
}
# Example
#
# $ mau:~> expandurl goo.gl/dUV6Su
# Location: http://www.mauriciohanika.de/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment