From ed9d057be3669ad24790aeb931dd677261db8d8e Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Wed, 17 Sep 2014 12:36:15 -0400 Subject: [PATCH] Tabs to spaces, small bit of cleanup --- LICENSE | 2 +- README.md | 17 +++++---- dry.css | 6 ++-- wet.css | 8 ++--- wetness | 106 +++++++++++++++++++++++++++--------------------------- 5 files changed, 71 insertions(+), 68 deletions(-) diff --git a/LICENSE b/LICENSE index 3bf0722..78400f8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Joshua John Sherman +Copyright (c) 2014 Josh Sherman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index c77b1c5..472c233 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -wetness -======= +# wetness `wetness` is a `bash` script for checking a CSS file for duplicate properties. Just like [Ellie Kemper][BJ], the aim of this script is to help make it DRY. @@ -8,15 +7,19 @@ This script utilizes associative arrays in `bash` which requires version 4 or better. OSX is still shipping with version 3.2 but you can easily upgrade to 4.2 with `brew install bash`. - [BJ]: http://www.collegehumor.com/video/1183463/derrick-comedy-blowjob - ## Usage - ./wetness /path/to/file.css +```sh +./wetness /path/to/file.css +``` ## Installation ### OSX via Homebrew - brew tap joshtronic/homebrew-formulae - brew install wetness +```sh +brew tap joshtronic/homebrew-formulae +brew install wetness +``` + + [BJ]: http://www.collegehumor.com/video/1183463/derrick-comedy-blowjob diff --git a/dry.css b/dry.css index 6b11054..f9ce9fe 100644 --- a/dry.css +++ b/dry.css @@ -1,15 +1,15 @@ body, html { - width: 100%; + width: 100%; } body { - font-size: 1em; + font-size: 1em; } .lead { - font-size: 150%; + font-size: 150%; } diff --git a/wet.css b/wet.css index 47f6592..abf087d 100644 --- a/wet.css +++ b/wet.css @@ -1,15 +1,15 @@ html { - width: 100%; + width: 100%; } body { - width: 100%; - font-size: 1em; + width: 100%; + font-size: 1em; } .lead { - font-size: 150%; + font-size: 150%; } diff --git a/wetness b/wetness index 5e3a299..3207c22 100755 --- a/wetness +++ b/wetness @@ -2,16 +2,16 @@ if [ -z $1 ]; then - echo 'Usage: wetness /path/to/file.css' - exit 1 + echo 'Usage: wetness /path/to/file.css' + exit 1 fi css_file=$1 if [ ! -e $css_file ]; then - echo 'Error: Supplied CSS file does not exist.' - exit 1 + echo 'Error: Supplied CSS file does not exist.' + exit 1 fi declare -A properties @@ -20,63 +20,63 @@ inside=false strip() { - echo `echo $1 | sed -e 's/^ *//g' -e 's/ *$//g' -e 's/;//'` + echo `echo $1 | sed -e 's/^ *//g' -e 's/ *$//g' -e 's/;//'` } cat $css_file | \ { - while read line - do - if [[ $line =~ '{' && ! $line =~ '//' ]] - then - inside=true - elif [[ $line =~ '}' && ! $line =~ '//' ]] - then - inside=false - elif [[ $inside == true && $line =~ ':' ]] - then - property=`echo $line | awk -F':' '{print $1}'` - property=`strip $property` - value=`echo $line | awk -F':' '{print $2}'` - value=`strip "$value"` + while read line + do + if [[ $line =~ '{' && ! $line =~ '//' ]] + then + inside=true + elif [[ $line =~ '}' && ! $line =~ '//' ]] + then + inside=false + elif [[ $inside == true && $line =~ ':' ]] + then + property=`echo $line | awk -F':' '{print $1}'` + property=`strip $property` + value=`echo $line | awk -F':' '{print $2}'` + value=`strip "$value"` - line="$property: $value;" + line="$property: $value;" - if [ ${properties[$line]+exists} ] - then - occurrences=$(( ${properties[$line]} + 1 )) - properties[$line]=$occurrences - dupes[$line]=$occurrences - else - properties[$line]=1 - fi - fi - done + if [ ${properties[$line]+exists} ] + then + occurrences=$(( ${properties[$line]} + 1 )) + properties[$line]=$occurrences + dupes[$line]=$occurrences + else + properties[$line]=1 + fi + fi + done - dupe_count=${#dupes[@]} + dupe_count=${#dupes[@]} - if [ $dupe_count == 0 ] - then - echo -e '\e[32mGREAT JOB! No duplicate properties were detected :)\e[0m' - else - echo -en "\e[31mGood try, but I found $dupe_count duplicated propert" - - if [ $dupe_count == 1 ] - then - echo -n 'y' - else - echo -n 'ies' - fi + if [ $dupe_count == 0 ] + then + echo -e '\e[32mGREAT JOB! No duplicate properties were detected :)\e[0m' + else + echo -en "\e[31mGood try, but I found $dupe_count duplicated propert" - echo -e " :(\e[0m" + if [ $dupe_count == 1 ] + then + echo -n 'y' + else + echo -n 'ies' + fi - for i in "${!dupes[@]}" - do - echo -en " \e[1;37m${dupes[$i]}\e[0m: \e[34m" - echo $i | awk -F':' '{print $1}' | tr -d '\n' - echo -en '\e[0m:\e[33m' - echo $i | awk -F':' '{print $2}' | tr -d '\n' - echo -e "\e[0m" - done - fi + echo -e " :(\e[0m" + + for i in "${!dupes[@]}" + do + echo -en " \e[1;37m${dupes[$i]}\e[0m: \e[34m" + echo $i | awk -F':' '{print $1}' | tr -d '\n' + echo -en '\e[0m:\e[33m' + echo $i | awk -F':' '{print $2}' | tr -d '\n' + echo -e "\e[0m" + done + fi }