Last active
December 17, 2015 11:18
-
-
Save sumpygump/5600704 to your computer and use it in GitHub Desktop.
istidy fetches and parses a URL and provides a report on HTML errors and warnings.
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 | |
# istidy will use the tidy program to fetch and parse a URL and provide a | |
# report on errors and warnings found. | |
# | |
# Usage: istidy <URL> | |
# Example: istidy http://google.com/ | |
# | |
# This script requires wget and tidy | |
# (apt-get install wget tidy) | |
: ${WGET=wget} | |
: ${TIDY=tidy} | |
HASERROR=false | |
red() { | |
if [ -t 0 ]; then | |
printf "\E[31m" | |
fi | |
} | |
op() { | |
if [ -t 0 ]; then | |
printf "\E[39;49m" | |
fi | |
} | |
# Assert required programs | |
assertRequirements() { | |
# Detect if wget is available | |
which $WGET > /dev/null | |
if [ $? -eq 1 ]; then | |
red; echo "Error: $WGET not installed. Please install first."; op | |
HASERROR=true | |
fi | |
# Detect if tidy is available | |
which $TIDY > /dev/null | |
if [ $? -eq 1 ]; then | |
red; echo "Error: $TIDY not installed. Please install first."; op | |
HASERROR=true | |
fi | |
if [ $HASERROR == true ]; then | |
echo "Goodbye." | |
exit 1; | |
fi | |
} | |
# Print usage | |
printUsage() { | |
echo "Usage: `basename $0` <URL>" | |
echo "This will fetch the HTML from the specified URL and display a report of errors from html tidy" | |
} | |
# Handle --help arg | |
if [ -n "$1" -a "$1" == "--help" ]; then | |
printUsage | |
exit 1 | |
fi | |
if [ -z $1 ]; then | |
printUsage | |
exit 2 | |
fi | |
assertRequirements | |
$WGET -q -O - "$1" | $TIDY -e 2>&1 | less -FX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment