Skip to content

Instantly share code, notes, and snippets.

@stubbornella
Forked from pjkix/css-stats-ack.sh
Created October 1, 2012 22:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stubbornella/3814765 to your computer and use it in GitHub Desktop.
Save stubbornella/3814765 to your computer and use it in GitHub Desktop.
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
## total rules
echo 'Rules:'
echo '----------'
ack --nogroup --css --match="{" -o -h | wc -l
## Layout
echo 'Layout:'
echo '----------'
echo -n "Left: "
ack --nogroup --css --match="left" -o -h | wc -l
echo -n "height: "
ack --nogroup --css --match="height" -o -h | wc -l
echo -n "width: "
ack --nogroup --css --match="width" -o -h | wc -l
echo -n "position: "
ack --nogroup --css --match="position" -o -h | wc -l
echo -n "Right: "
ack --nogroup --css --match="right" -o -h | wc -l
echo -n "Display: "
ack --nogroup --css --match="display" -o -h | wc -l
echo -n "Float: "
ack --nogroup --css --match="float" -o -h | wc -l
echo
## colors
echo 'Colors:'
echo '----------'
echo -n "Color: "
ack --nogroup --css --match="color" -o -h | wc -l
echo -n "White: "
ack --nogroup --css --match="(#[fF]{3,6}|white)" -o -h | wc -l
echo -n "Background: "
ack --nogroup --css --match="background" -o -h | wc -l
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment