forked from mintty/mintty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getflags
executable file
·113 lines (101 loc) · 2.87 KB
/
getflags
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
#! /bin/sh
#############################################################################
# download function
download () {
# download Google region flags
if type svn
then svn export https://github.com/google/region-flags/trunk/png google-region-flags
else git clone --depth 1 https://github.com/google/region-flags.git google-region-flags &&
ln google-region-flags/png/*.png google-region-flags/
fi
# download Puellanivis’ flag emojis
git clone --depth 1 https://github.com/puellanivis/emoji.git puellanivis-flags &&
(cd puellanivis-flags/flags; ln *.png */*.png ..)
}
#############################################################################
# extract emoji files:
# pre-deploy them with proper filename, according to codepoint pattern
extract () {
mkdir -p common
for f in `ls *-flags/*.png`
do e=${f##*/}
e=${e%.png}
if [ -n "$BASH_VERSION" ]
then
e=${e//-}
e=${e//\'}
#else filter them out by missing case below
fi
case $e in
??) # 1F1E6 1F1E8 ; RGI_Emoji_Flag_Sequence
tagseq=false;;
*) # 1F3F4 E0067 E0062 E0065 E006E E0067 E007F; RGI_Emoji_Tag_Sequence; flag: England
tagseq=true;;
esac
if $tagseq
then n=1f3f4
else n=
fi
# speed-up possible by using a common sed script...
for l in $( echo "$e" | tr 'A-Z' 'a-z' | sed -e 's,.,& ,g' )
do d=$( printf %d "'$l'" )
if $tagseq
then case "$l" in
[a-z]|[0-9])
d=$(( $d + 917504 ))
n=$n-$( printf %x $d )
;;
#[a-z]) d=$(( $d - 97 + 917601 )) # 'a' -> U+E0061 ...
# n=$n-$( printf %x $d )
# ;;
#[0-9]) d=$(( $d - 48 + 917552 )) # '0' -> U+E0030 ...
# n=$n-$( printf %x $d )
# ;;
esac
else d=$(( $d - 97 + 127462 )) # U+1F1E6
n=$n-$( printf %x $d )
fi
done
if $tagseq
then n=$n-e007f.png
else n=${n#-}.png
fi
echo "$f -> common/$n"
ln "$f" "common/$n"
done
}
#############################################################################
# perform download and extraction/deployment
case "$1" in
""|-h|--help)
echo "Usage: `basename $0` [-d | -e | -de]" >&2
echo >&2
echo "This script retrieves flag emojis from various sources." >&2
echo >&2
echo "Options:" >&2
echo " -d Download flags emojis repositories" >&2
echo " -e Extract emoji files with proper filenames into common/" >&2
echo " -de -d and -e" >&2
echo >&2
if [ `uname` = "Linux" ] && type wslpath 2> /dev/null 1>&2
then echo "Note: for direct deployment from WSL, first go into the common config directory:" >&2
echo ' cd `wslpath "$APPDATA/mintty/emojis"` || cd `wslpath "$APPDATA/wsltty/emojis"`' >&2
else 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
fi
exit;;
-d|--download)
download
;;
-e|--extract)
extract
;;
-de|--all)
download
extract
;;
esac