Created
June 11, 2011 00:29
-
-
Save markandrus/1020086 to your computer and use it in GitHub Desktop.
List CSS class and id usage within a directory of files
This file contains hidden or 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/sh | |
| # stylecheck.sh: | |
| # | |
| # Find unused CSS class and id selectors, given a CSS file and a directory | |
| # of HTML documents. | |
| # | |
| # $1 = CSS document, $2 = HTML directory | |
| # | |
| # Returns a report in YAML. | |
| # | |
| # by Mark | |
| echo -e "# Analyzing usage of $1 in $0\n---" | |
| classes=`grep -o -P '(?<=\.)[a-zA-Z][a-zA-z0-9_\-]*(?=([ ,\n]*[a-zA-Z0-9_\-#\.\:]*)*{)' <"$1" | sort | uniq` | |
| ids=`grep -o -P '(?<=#)[a-zA-Z][a-zA-z0-9_\-]*(?=([ ,\n]*[a-zA-Z0-9_\-#\.\:]*)*{)' <"$1" | sort | uniq` | |
| echo "CSS classes:" | |
| for s in $classes; do | |
| echo " $s:" | |
| for f in `ack "class=\"( |[a-zA-Z0-9]|-)*$s( |[a-zA-Z0-9]|-)*\"" $2 --type=nocss -l`; do | |
| echo " - $f" | |
| done | |
| done | |
| echo -e "\nCSS ids:" | |
| for s in $ids; do | |
| echo " $s:" | |
| for f in `ack "id=\"$s\"" $2 --type=nocss -l`; do | |
| echo " - $f" | |
| done | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment