Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
shell script to generate some css file statistics
#!/bin/bash
## v1.0.6
## this script will gernerate css stats
### example output
# CSS STATS
# ----------
# Floats: 132
# Headings: 107
# Margins: 432
# Paddings: 463
# Font-Sizes: 170
# Importants: 56
echo 'CSS STATS'
echo '========='
echo
echo 'General: '
echo '----------'
## number of files
echo -n "Number of CSS files: "
ack --css -f | wc -l
## number of lines
# ack --nogroup --css --passthru * | wc -l | xargs echo "Number of Lines of Code (LoC)"
## longest file
echo 'File Length (LoC):'
find . -iname "*.css" | xargs wc -l | sort -r
echo
echo 'File Size (KBytes)'
# find . -iname "*.css" | xargs ls -l | awk '{print $5 "\t" $9}' | sort -nr ## Bytes
# find . -iname "*.css" | xargs ls -l | awk '{printf("%.1fK\t", $5 / 1024); print "\t" $9}' | sort -nr ## KB
find . -iname "*.css" -print0 | xargs -0 du -hsc | sort -nr ## block size
# find . -iname "*.css" -print0 | du -hsc ## block size
# stat -f "%z Bytes" stats.sh ## actual file size in bytes
echo
echo 'Props: '
echo '----------'
## append search results
# echo -n "test:"
echo -n "Floats: "
ack --nogroup --css float | wc -l
echo -n "Headings: "
ack --nogroup --css h[1-6] | wc -l
echo -n "Margins: "
ack --nogroup --css margin | wc -l
echo -n "Margins 0: "
ack --nogroup --css --match="margin-?(top|right|bottom|left)?\s*:\s*0" | wc -l
echo -n "Paddings: "
ack --nogroup --css padding | wc -l
echo -n "Padding 0: "
ack --nogroup --css --match="padding-?(top|right|bottom|left)?\s*:\s*0" | wc -l
echo -n "Font-Sizes: "
ack --nogroup --css font-size | wc -l
echo -n "Importants: "
ack --nogroup --css important | wc -l
echo
## colors
echo 'Colors:'
echo '----------'
echo -n "Hex: "
ack --nogroup --css --match="#[0-9a-fA-F]{3,6}" -o -h | wc -l
echo -n "RGB(a): "
ack --nogroup --css --match="rgba?\w*\(.*\)" -o -h | wc -l
echo
### unique
echo 'Unique Colors:'
echo '----------'
echo -n 'Hex: '
ack --nogroup --css --match="#[0-9a-fA-F]{3,6}" -o -h | sort | uniq -i -c | wc -l
echo
ack --nogroup --css --match="#[0-9a-fA-F]{3,6}" -o -h | sort | uniq -i -c | sort -r
echo
echo -n 'RGB(a): '
ack --nogroup --css --match="rgba?\w*\(.*\)" -o -h | sort | uniq -i -c | wc -l
echo
ack --nogroup --css --match="rgba?\w*\(.*\)" -o -h | sort | uniq -i -c | sort -r
echo
## Images
echo "Images:"
echo '----------'
echo -n "URLs:"
ack --nogroup --css --match="url\w?\(.*\)" -o -h | wc -l
### unique urls
echo -n "Unique URLs:"
ack --nogroup --css --match="url\w?\(.*\)" -o -h | sort | uniq -i -c | wc -l
echo
ack --nogroup --css --match="url\w?\(.*\)" -o -h | sort | uniq -i -c | sort -r
@pjkix

This comment has been minimized.

Copy link
Owner Author

commented Sep 30, 2012

Note: this script uses ack instead of grep http://betterthangrep.com/
it's also recommended that you place this script int a folder on your path such as ~/bin or /usr/local/bin so you can cd to any folder and call the script from there

@stubbornella

This comment has been minimized.

Copy link

commented Oct 1, 2012

I've been adding stuff to this... I think I need to figure out how to make a function soon, because I'm writing the same stuff over and over. :)

@stubbornella

This comment has been minimized.

Copy link

commented Oct 1, 2012

Also, a note for mac users. ack can be installed by installing the command line tools rather than all of Xcode. https://developer.apple.com/downloads/index.action

@ghost

This comment has been minimized.

Copy link

commented Oct 1, 2012

How do you call this script? Do you just call it from within your project folder?

@ghost

This comment has been minimized.

Copy link

commented Oct 1, 2012

It's picking up custom fonts (@font-family) files as images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.