Tabs to spaces, small bit of cleanup

This commit is contained in:
Josh Sherman 2014-09-17 12:36:15 -04:00
parent ef9c2860b1
commit ed9d057be3
5 changed files with 71 additions and 68 deletions

View file

@ -1,6 +1,6 @@
The MIT License (MIT) 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 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 this software and associated documentation files (the "Software"), to deal in

View file

@ -1,5 +1,4 @@
wetness # wetness
=======
`wetness` is a `bash` script for checking a CSS file for duplicate properties. `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. 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 better. OSX is still shipping with version 3.2 but you can easily upgrade to
4.2 with `brew install bash`. 4.2 with `brew install bash`.
[BJ]: http://www.collegehumor.com/video/1183463/derrick-comedy-blowjob
## Usage ## Usage
./wetness /path/to/file.css ```sh
./wetness /path/to/file.css
```
## Installation ## Installation
### OSX via Homebrew ### OSX via Homebrew
brew tap joshtronic/homebrew-formulae ```sh
brew install wetness brew tap joshtronic/homebrew-formulae
brew install wetness
```
[BJ]: http://www.collegehumor.com/video/1183463/derrick-comedy-blowjob

View file

@ -1,15 +1,15 @@
body, body,
html html
{ {
width: 100%; width: 100%;
} }
body body
{ {
font-size: 1em; font-size: 1em;
} }
.lead .lead
{ {
font-size: 150%; font-size: 150%;
} }

View file

@ -1,15 +1,15 @@
html html
{ {
width: 100%; width: 100%;
} }
body body
{ {
width: 100%; width: 100%;
font-size: 1em; font-size: 1em;
} }
.lead .lead
{ {
font-size: 150%; font-size: 150%;
} }

104
wetness
View file

@ -2,16 +2,16 @@
if [ -z $1 ]; if [ -z $1 ];
then then
echo 'Usage: wetness /path/to/file.css' echo 'Usage: wetness /path/to/file.css'
exit 1 exit 1
fi fi
css_file=$1 css_file=$1
if [ ! -e $css_file ]; if [ ! -e $css_file ];
then then
echo 'Error: Supplied CSS file does not exist.' echo 'Error: Supplied CSS file does not exist.'
exit 1 exit 1
fi fi
declare -A properties declare -A properties
@ -20,63 +20,63 @@ inside=false
strip() 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 | \ cat $css_file | \
{ {
while read line while read line
do do
if [[ $line =~ '{' && ! $line =~ '//' ]] if [[ $line =~ '{' && ! $line =~ '//' ]]
then then
inside=true inside=true
elif [[ $line =~ '}' && ! $line =~ '//' ]] elif [[ $line =~ '}' && ! $line =~ '//' ]]
then then
inside=false inside=false
elif [[ $inside == true && $line =~ ':' ]] elif [[ $inside == true && $line =~ ':' ]]
then then
property=`echo $line | awk -F':' '{print $1}'` property=`echo $line | awk -F':' '{print $1}'`
property=`strip $property` property=`strip $property`
value=`echo $line | awk -F':' '{print $2}'` value=`echo $line | awk -F':' '{print $2}'`
value=`strip "$value"` value=`strip "$value"`
line="$property: $value;" line="$property: $value;"
if [ ${properties[$line]+exists} ] if [ ${properties[$line]+exists} ]
then then
occurrences=$(( ${properties[$line]} + 1 )) occurrences=$(( ${properties[$line]} + 1 ))
properties[$line]=$occurrences properties[$line]=$occurrences
dupes[$line]=$occurrences dupes[$line]=$occurrences
else else
properties[$line]=1 properties[$line]=1
fi fi
fi fi
done done
dupe_count=${#dupes[@]} dupe_count=${#dupes[@]}
if [ $dupe_count == 0 ] if [ $dupe_count == 0 ]
then then
echo -e '\e[32mGREAT JOB! No duplicate properties were detected :)\e[0m' echo -e '\e[32mGREAT JOB! No duplicate properties were detected :)\e[0m'
else else
echo -en "\e[31mGood try, but I found $dupe_count duplicated propert" echo -en "\e[31mGood try, but I found $dupe_count duplicated propert"
if [ $dupe_count == 1 ] if [ $dupe_count == 1 ]
then then
echo -n 'y' echo -n 'y'
else else
echo -n 'ies' echo -n 'ies'
fi fi
echo -e " :(\e[0m" echo -e " :(\e[0m"
for i in "${!dupes[@]}" for i in "${!dupes[@]}"
do do
echo -en " \e[1;37m${dupes[$i]}\e[0m: \e[34m" echo -en " \e[1;37m${dupes[$i]}\e[0m: \e[34m"
echo $i | awk -F':' '{print $1}' | tr -d '\n' echo $i | awk -F':' '{print $1}' | tr -d '\n'
echo -en '\e[0m:\e[33m' echo -en '\e[0m:\e[33m'
echo $i | awk -F':' '{print $2}' | tr -d '\n' echo $i | awk -F':' '{print $2}' | tr -d '\n'
echo -e "\e[0m" echo -e "\e[0m"
done done
fi fi
} }