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)
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

View file

@ -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

View file

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

View file

@ -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%;
}

104
wetness
View file

@ -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 == 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 == 1 ]
then
echo -n 'y'
else
echo -n 'ies'
fi
echo -e " :(\e[0m"
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
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
}