Skip to content

Instantly share code, notes, and snippets.

@correlator
Forked from 50kudos/flashflush.sh
Created September 4, 2017 22:59
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 correlator/974ff8349d54968d9c4f6f6f9be6a113 to your computer and use it in GitHub Desktop.
Save correlator/974ff8349d54968d9c4f6f6f9be6a113 to your computer and use it in GitHub Desktop.
A Bash script that lists all unused css classes in html/haml/erb files for rails project (or maybe others depending on project structure)
#!/bin/bash
cat $(find app/assets/stylesheets/ -type f) |
grep -Eo '\.[a-z]+[a-z0-9_-]*' | sort | uniq | sed s/.// |
while read CSS; do
if ! grep -Erqi "([^(remove|has)]?class[(:|=|[:space:]*=>[:space:]*)]*[[:space:]\W]*[(\"|')]*[-a-z0-9[:space:]]*$CSS|\\.$CSS\b)" app/views/ vendor/assets/ app/assets/javascripts/; then
echo $CSS >> unused.scss;
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment