Skip to content

Instantly share code, notes, and snippets.

@Donearm
Forked from pjkix/css-stats-ack.sh
Created October 14, 2012 15:42
Show Gist options
  • Save Donearm/3888964 to your computer and use it in GitHub Desktop.
Save Donearm/3888964 to your computer and use it in GitHub Desktop.
shell script to generate some css file statistics
#!/bin/bash
## v1.0.7
## this script will gernerate css stats
### example output
# CSS STATS
# ----------
# Floats: 132
# Headings: 107
# Margins: 432
# Paddings: 463
# Font-Sizes: 170
# Importants: 56
CSS_FILES=$(ls "$@")
echo 'CSS STATS'
echo '========='
echo
echo 'General: '
echo '----------'
## number of files
echo -n "Number of CSS files: "
ls $CSS_FILES | wc -l
## number of lines
# cat * | 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: "
grep -c float $CSS_FILES | wc -l
echo -n "Headings: "
grep "h[1-6]" $CSS_FILES | wc -l
echo -n "Margins: "
grep margin $CSS_FILES | wc -l
echo -n "Margins 0: "
grep "margin-\?\(top\|right\|bottom\|left\)\?[[:space:]]*:[[:space:]]*0" $CSS_FILES | wc -l
echo -n "Paddings: "
grep padding $CSS_FILES | wc -l
echo -n "Padding 0: "
grep "padding-\?\(top\|right\|bottom\|left\)\?[[:space:]]*:[[:space:]]*0" $CSS_FILES | wc -l
echo -n "Font-Sizes: "
grep font-size $CSS_FILES | wc -l
echo -n "Importants: "
grep important $CSS_FILES | wc -l
echo
## colors
echo 'Colors:'
echo '----------'
echo -n "Hex: "
grep "color:[[:space:]]*#[0-9a-fA-F]\{3,6\}" -h $CSS_FILES | wc -l
echo -n "RGB(a): "
grep "rgba\?[[:alnum:]]*\(.*\)" -h $CSS_FILES | wc -l
echo
### unique
echo 'Unique Colors:'
echo '----------'
echo -n 'Hex: '
grep "color:[[:space:]]*#[0-9a-fA-F]\{3,6\}" -h $CSS_FILES | sort | uniq -i -c | wc -l
echo
grep "color:[[:space:]]*#[0-9a-fA-F]\{3,6\}" -h $CSS_FILES -o | sort | uniq -i -c | sort -r
echo
echo -n 'RGB(a): '
grep "rgba\?[[:alnum:]]*\(.*\)" -h $CSS_FILES | sort | uniq -i -c | wc -l
echo
grep "rgba\?[[:alnum:]]*\(.*\)" -h $CSS_FILES | sort | uniq -i -c | sort -r
echo
## Images
echo "Images:"
echo '----------'
echo -n "URLs:"
grep "url[[:alnum:]]\?\(.*\)" -h $CSS_FILES | wc -l
### unique urls
echo -n "Unique URLs:"
grep "url[[:alnum:]]\?\(.*\)" -h $CSS_FILES | sort | uniq -i -c | wc -l
echo
grep "url[[:alnum:]]\?\(.*\)" -h -o $CSS_FILES | sort | uniq -i -c | sort -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment