Skip to content

Instantly share code, notes, and snippets.

@danreeves
Last active December 30, 2015 21:39
Show Gist options
  • Save danreeves/7888969 to your computer and use it in GitHub Desktop.
Save danreeves/7888969 to your computer and use it in GitHub Desktop.
What Is Status Code ... ? Grabs the name of the status code you enter from Wikipedia. e.g: ```` --> wisc 404 404 Not Found ````
#!/bin/zsh
if [[ $1 == '' ]]; then
print 'Please pass in a status code, e.g. 404'
exit 2
fi
A='/\>('
B='[^\<]*?)\</ and print $1'
REGEX=$A$1$B
MATCH=`curl -s http://en.wikipedia.org/wiki/List_of_HTTP_status_codes | perl -l -ne $REGEX`
if [[ $MATCH == '' ]]; then
print "Nothing matched '$1'"
else
FIRST=("${(f)MATCH}")
print $FIRST[1]
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment