This repository has been archived by the owner on Apr 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inquisition.sh
executable file
·68 lines (54 loc) · 1.68 KB
/
inquisition.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
ereticlist="${1}"
originalfile="${2}"
if [ $# -ne 2 ]; then
echo ""
echo " Usage: $0 <list> <target file>"
echo " <list> is a file containg the list of unused classes that need to be removed, 1 per line, no trailing {"
echo " <target file> is a non minified CSS file (1 line 1 rule)"
echo ""
exit
fi
function speak() {
echo "[$(date +%H:%M:%S)] $@"
}
function checkforeresy() {
if [ -e "$@" ]; then
if [ ! -r "$@" ]; then
#If it exist but is not readable we notify
speak "[NOTICE] $@ not readable, quitting."
exit
fi
else
speak "[ERROR] $@ doesn't exist, quitting."
exit
fi
}
speak "Beginning inquisition"
checkforeresy "$ereticlist"
checkforeresy "$originalfile"
if [ -e "clean-${originalfile}" ]; then
speak "[ERROR] clean-${originalfile} already exist, remove it before executing this script again, quitting."
exit
fi
initiallines=$( cat "${originalfile}" | wc -l )
speak "Detected ${initiallines} lines in ${originalfile}"
cp "${originalfile}" clean-"${originalfile}"
cleanfile="clean-${originalfile}"
speak "Created ${cleanfile}"
(cat "${ereticlist}";echo) | while read eretic; do
if [ -z "${eretic}" ]; then
continue
fi
if grep -q "," <<< "${eretic}"; then
eretic=$(echo "${eretic}" | sed 's/, /,/g')
fi
eretic=$(echo "${eretic}" | sed 's/\"/\\"/g'| sed 's/\#/\\#/g' | sed 's/\[/\\[/g' | sed 's/\]/\\]/g')
grep -v "^${eretic} {" "${cleanfile}" > "1-${cleanfile}"
mv "1-${cleanfile}" "${cleanfile}"
grep -v "^${eretic}{" "${cleanfile}" > "1-${cleanfile}"
mv "1-${cleanfile}" "${cleanfile}"
done
newlines=$( cat "${cleanfile}" | wc -l )
finallines=$(( (${initiallines} - ${newlines}) ))
speak "Removed ${finallines} lines."