-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unCompress.bash
executable file
·36 lines (30 loc) · 1.29 KB
/
unCompress.bash
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
#!/bin/bash
#Author: Michael Bianco, http://developer.mabwebdesign.com/, <software@mabwebdesign.com>
#Description: This script will uncompress CSS files compressed with CSS Optimizer (http://developer.mabwebdesign.com/cssoptimizer.html)
# This script requires the GNU version of the sed command, change the SED_COMMAND variable to represent the path to your GNU sed
# You can download GNU sed via fink if you dont have it, or compile it from source at: http://directory.fsf.org/GNU/sed.html
SED_COMMAND=/usr/bin/fsed #path to GNU sed
if [ ! -e "$1" ]; then
echo "Enter a valid input file."
exit 1
fi
if [ -z "$2" ] && [ -e "$2" ]; then
echo "File:'$2' already exists. Clear file for output? (y/n)"
read
if [ $REPLY == "n" ]; then
echo "Please try running the script with another output file."
exit 2
else
OUTPUT_FILE="$2"
fi
elif [ -z "$2" ]; then
OUTPUT_FILE="$1"
else
OUTPUT_FILE="$2"
fi
cat "$1" | "$SED_COMMAND" 's/[;{]/&\n\t/g' | \ #do main formatting for all CSS properties and the beggining of CSS declerations
"$SED_COMMAND" 's/\([^}]\)\(}\)/\1;\n\2\n\n/g' | \ #end of decleration formatting
"$SED_COMMAND" 's/{/ {/g' | \ #more beggining of CSS decleration
"$SED_COMMAND" 's/[:,]/& /g' \ #add some spaces for readability
> "$OUTPUT_FILE" #output the result
exit 0