Skip to content

Commit 2b3ab58

Browse files
committed
1.4: simplify
1 parent 59cdb7d commit 2b3ab58

File tree

3 files changed

+43
-55
lines changed

3 files changed

+43
-55
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Bash script for clean html file in console.
99
Example:
1010

1111
```bash
12-
$ bash clean-html-js.sh -c index.html
12+
$ bash clean-html-js.sh -i index.html
1313

1414
clean-html-js.sh version 1.3
1515
index.html -> index.utf8.html

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3
1+
1.4

clean-html-js.sh

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
#!/bin/bash
22
# clean-html-js.sh
33

4-
VER="1.3"
5-
GREEN="\033[1;32m"
6-
RED="\033[0;31m"
7-
YELLOW="\033[1;33m"
8-
ENDCOLOR="\033[0m"
4+
VER="1.4"
95

106
tproc=`basename $0`
11-
echo -e $GREEN"$tproc version $VER"$ENDCOLOR
7+
echo -e "$tproc version $VER"
128
echo ""
139

1410
usage()
1511
{
1612
tproc=`basename $0`
17-
echo -e $YELLOW"usage:"$ENDCOLOR
18-
echo -e $GREEN" bash $tproc input.html"$ENDCOLOR
13+
echo -e "usage:"
14+
echo -e " bash $tproc input.html"
1915
echo "options:"
20-
echo " -c not clean comment (default = false);"
16+
echo " -c clean comment (default = false);"
17+
echo " -i iconvert (default = false);"
2118
echo " -n not verify type file (default = false);"
2219
echo " -o str output path (default = input.utf8.html);"
2320
echo " -r rewrite file (default = false);"
@@ -29,45 +26,30 @@ usage()
2926
testcomponent()
3027
{
3128
tnocomp=""
32-
tcomp="/usr/bin/iconv"
33-
tdeb="libc-bin_*.deb"
34-
if [ ! -f "$tcomp" ]
29+
tcomp="iconv"
30+
[ ! "$(command -v $tcomp)" ] && tnocomp="$tnocomp $tcomp"
31+
tcomp="enca"
32+
[ ! "$(command -v $tcomp)" ] && tnocomp="$tnocomp $tcomp"
33+
tcomp="sed"
34+
[ ! "$(command -v $tcomp)" ] && tnocomp="$tnocomp $tcomp"
35+
tcomp="grep"
36+
[ ! "$(command -v $tcomp)" ] && tnocomp="$tnocomp $tcomp"
37+
if [ "x$tnocomp" != "x" ]
3538
then
36-
tnocomp="$tnocomp $tcomp($tdeb)"
37-
fi
38-
tcomp="/usr/bin/enca"
39-
tdeb="enca_*.deb"
40-
if [ ! -f "$tcomp" ]
41-
then
42-
tnocomp="$tnocomp $tcomp($tdeb)"
43-
fi
44-
tcomp="/bin/sed"
45-
tdeb="sed_*.deb"
46-
if [ ! -f "$tcomp" ]
47-
then
48-
tnocomp="$tnocomp $tcomp($tdeb)"
49-
fi
50-
tcomp="/bin/grep"
51-
tdeb="grep_*.deb"
52-
if [ ! -f "$tcomp" ]
53-
then
54-
tnocomp="$tnocomp $tcomp($tdeb)"
55-
fi
56-
if [ "+$tnocomp" != "+" ]
57-
then
58-
echo -e $RED"Not found $tnocomp !"$ENDCOLOR
59-
echo ""
60-
exit 0
39+
echo "Not found:${tnocomp}!"
40+
exit 1
6141
fi
6242
}
6343

6444
main()
6545
{
66-
while getopts ":cno:rh" opt
46+
while getopts ":cino:rh" opt
6747
do
6848
case $opt in
6949
c) tcomment="1"
7050
;;
51+
i) ticonv="1"
52+
;;
7153
n) tnoverify="1"
7254
;;
7355
o) tdest="$OPTARG"
@@ -87,8 +69,6 @@ if [ -z "$SRCNAME" ]
8769
then
8870
usage
8971
fi
90-
echo "$src"
91-
echo ""
9272
if [ -z "$tnoverify" ]
9373
then
9474
thtml=`file "$SRCNAME" | grep "HTML document"`
@@ -101,15 +81,20 @@ then
10181
NEWNAME="$NEWNAME.utf8.html"
10282
echo " $SRCNAME -> $NEWNAME"
10383

104-
CODENAME=$(/usr/bin/enca -i "$SRCNAME")
105-
if [ "+$CODENAME" = "+" -o "+$CODENAME" = "+???" ]
106-
then
107-
CODENAME="UTF-8"
108-
elif [ "+$CODENAME" != "+UTF-8" ]
84+
if [ -z "$ticonv" ]
10985
then
110-
echo " Convert: $CODENAME -> UTF8"
86+
cat "$SRCNAME" > "$NEWNAME"
87+
else
88+
CODENAME=$(enca -i "$SRCNAME")
89+
if [ "+$CODENAME" = "+" -o "+$CODENAME" = "+???" ]
90+
then
91+
CODENAME="UTF-8"
92+
elif [ "+$CODENAME" != "+UTF-8" ]
93+
then
94+
echo " Convert: $CODENAME -> UTF8"
95+
fi
96+
cat "$SRCNAME" | iconv -c -f ${CODENAME} -t UTF8 > "$NEWNAME"
11197
fi
112-
cat "$SRCNAME" | iconv -c -f ${CODENAME} -t UTF8 > "$NEWNAME"
11398

11499
echo -e -n "[4]: 0.."
115100

@@ -154,7 +139,7 @@ echo -e -n "2.."
154139

155140
echo -e -n "3.."
156141

157-
if [ -z "$tcomment" ]
142+
if [ ! -z "$tcomment" ]
158143
then
159144
sed -i -e '
160145
/^<\!--/,/^-->/d
@@ -163,11 +148,14 @@ echo -e -n "3.."
163148

164149
echo -e -n "4.."
165150

166-
sed -i -e '
167-
s/content="text\/html; charset=.*">/content="text\/html; charset=utf-8">/ig
168-
s/[ \t]*$//
169-
/^$/d
170-
' "$NEWNAME"
151+
if [ ! -z "$ticonv" ]
152+
then
153+
sed -i -e '
154+
s/content="text\/html; charset=.*">/content="text\/html; charset=utf-8">/ig
155+
s/[ \t]*$//
156+
/^$/d
157+
' "$NEWNAME"
158+
fi
171159

172160
flgpre=`grep -i "<pre" "$NEWNAME"`
173161
if [ "+$flgpre" = "+" ]

0 commit comments

Comments
 (0)