forked from mintty/mintty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetemojis
executable file
·205 lines (182 loc) · 4.51 KB
/
getemojis
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#! /bin/sh
trace () {
# echo $* >&2
true
}
case "$1" in
-sh) postproc=cat
shift;;
*) postproc=sh;;
esac
case `basename "$PWD"` in
mintty)
echo "You seem to be in a mintty config directory:" >&2
echo " $PWD" >&2
echo "For direct emoji deployment, run this script from its subdirectory 'emojis'." >&2
exit;;
esac
emojisurl0=http://www.unicode.org/emoji/charts/full-emoji-list.html
emojisurl1=http://www.unicode.org/emoji/charts/full-emoji-modifiers.html
download () {
if type curl
then curl -RO -z `basename $1` $1
else wget -N -t 1 $1
fi
}
case "$1" in
""|-h|--help)
echo "Usage: `basename $0` [-d | DIR | .../full-emoji-list.html] [EMOJI_STYLE]..." >&2
echo >&2
echo "This script extracts emojis graphics (.png format) from a downloaded copy of" >&2
echo " $emojisurl0" >&2
echo " $emojisurl1" >&2
echo "for the selected emoji style sets, or (if none selected) all of them:" >&2
echo " apple google facebook windows twitter emojione samsung" >&2
echo "and always extracts common emoji graphics." >&2
echo >&2
echo "Options:" >&2
echo " -d Download the chart files" >&2
echo " DIR Expect the chart files in given directory" >&2
echo >&2
echo "Warning: with all styles selected, this may take a while." >&2
echo >&2
echo "Note: for direct deployment, first go into subdirectory 'emojis' of one of the" >&2
echo "mintty config directories:" >&2
echo ' ~/.mintty' >&2
echo ' ~/.config/mintty' >&2
echo ' $APPDATA/mintty' >&2
echo ' /usr/share/mintty' >&2
exit;;
-d|--download)
if download $emojisurl0 && download $emojisurl1
then emojis0=full-emoji-list.html
emojis1=full-emoji-modifiers.html
else echo Download failed >&2
exit
fi
shift;;
*.html) emojis1=`dirname "$1"`/full-emoji-modifiers.html
if [ -r "$1" -a -r "$emojis1" ]
then emojis0="$1"
else echo Not readable: "$1" "$emojis1" >&2
exit
fi
shift;;
*) if [ -d "$1" ]
then emojis0="$1"/full-emoji-list.html
emojis1="$1"/full-emoji-modifiers.html
if [ -r "$emojis0" -a -r "$emojis1" ]
then true
else echo Not readable: "$emojis0" "$emojis1" >&2
exit
fi
shift
else echo Missing file name of full emoji list >&2
exit
fi;;
esac
echo -n "Using " >&2
cat "$emojis0" | sed -e "s,<title>\(.*\)</title>,\1," -e t -e d >&2
#cat "$emojis0" |
#sed -e "/^<\/tr/ q" -e "s/.*<th.*#col-vendor.>\([^.<]*\).*/\1/" -e t -e d |
#pr -t -n | sed -e "s,^,vendor ," -e 7q
# 11.0:
# vendor 1 Appl
# vendor 2 Goog
# vendor 3 Twtr
# vendor 4 One
# vendor 5 FB
# vendor 6 Sams
# vendor 7 Wind
# 12.0:
# vendor 1 Appl
# vendor 2 Goog
# vendor 3 FB
# vendor 4 Wind
# vendor 5 Twtr
# vendor 6 Joy
# vendor 7 Sams
seli=0
for vendor in `cat "$emojis0" |
sed -e "/^<\/tr/ q" -e "s/.*<th.*#col-vendor.>\([^.<]*\).*/\1/" -e t -e d |
sed -e 7q`
do seli=`expr $seli + 1`
case "$vendor" in
Appl) apple=$seli;;
Goog) google=$seli;;
FB) facebook=$seli;;
Wind) windows=$seli;;
Twtr) twitter=$seli;;
One|Joy) emojione=$seli;;
Sams) samsung=$seli;;
esac
done
case "$1" in
"") set - apple google facebook windows twitter emojione samsung;;
esac
sel=
while case "$1" in
apple) seli="$apple";;
google) seli="$google";;
facebook) seli="$facebook";;
windows) seli="$windows";;
twitter) seli="$twitter";;
joy|emojione) seli="$emojione";;
samsung) seli="$samsung";;
"") false;;
*) echo emoji set "$1" not known; exit;;
esac
do sel="$sel$seli"
mkdir -p "$1"
[ -e "$seli" ] || ln -s "$1" "$seli"
shift
done
mkdir -p common
[ -e 0 ] || ln -s common 0
export sel
echo "Warning: this may take a few hours on Cygwin" >&2
LC_ALL=C
export LC_ALL
total=`grep -e "name='\([^']*\)'.*U+" "$emojis0" "$emojis1" | wc -l`
export total
(
echo "Extracting $total emojis " >&2
echo LC_ALL=C
echo export LC_ALL
echo total=$total
echo sel=$sel
cat <<\/EOS
n=0
name () {
ename=$1
style=0
n=$(( $n + 1 ))
p=$(( ${n}00 / $total ))
echo "emoji $ename (${p}%)" >&2
}
img0 () {
echo " common 0/$ename.png" >&2
echo "$1" | base64 -d > 0/$ename.png
}
img () {
style=$(( $style + 1 ))
case $sel in
*$style*) echo "$1" | base64 -d > $style/$ename.png;;
esac
}
imgskip () {
style=$(( $style + 1 ))
case $sel in
*$style*) echo " skip $style/$ename.png" >&2;;
esac
}
/EOS
cat "$emojis0" "$emojis1" |
sed -e "s/^.*name='\([^']*\)'.*U+.*/name \1/" -e "t name" \
-e "s/.*—.*/imgskip/" -e t \
-e "s@^.*….*src='data:image/png;base64,\([^']*\)'.*@img0 \1@" -e t \
-e "s@^.*src='data:image/png;base64,\([^']*\)'.*@img \1@" -e t \
-e d \
-e ": name" \
-e "s,_,-,g"
) | $postproc