codekingpro/portable-devtools
114k
1#! /bin/dash2 3# this script is 20% faster with dash than with bash4 5#############################################################################6# download function7 8download_noto () {9 10# download noto third-party region flags11if [ -d noto-emoji-flags ]12then if [ -d noto-emoji-flags/.git ]13 then (cd noto-emoji-flags; git pull)14 else echo WARNING: directory noto-emoji-flags already exists but no git config - Exit15 exit 916 fi17else18 notogit=https://github.com/googlefonts/noto-emoji19 git clone --depth 1 -n --filter=blob:none $notogit noto-emoji-flags20 (cd noto-emoji-flags21 git sparse-checkout set --no-cone third_party/region-flags/png22 git checkout23 )24fi25(cd noto-emoji-flags; rm -f *.png; ln third_party/region-flags/png/*.png ./)26 27}28 29download_other () {30 31# download Puellanivis’ flag emojis32if [ -d puellanivis-flags ]33then if [ -d puellanivis-flags/.git ]34 then (cd puellanivis-flags; git pull)35 else echo WARNING: directory puellanivis-flags already exists but no git config - Exit36 exit 937 fi38else39 puelgit=https://github.com/puellanivis/emoji.git40 git clone --depth 1 $puelgit puellanivis-flags41fi42(cd puellanivis-flags; rm -f *.png; ln flags/*.png flags/*/*.png ./)43 44}45 46download () {47 download_noto48 49 # drop download of old Google region flags50 #git clone --depth 1 https://github.com/google/region-flags.git google-region-flags &&51 #ln google-region-flags/png/*.png google-region-flags/52 53 download_other54}55 56#############################################################################57# extract emoji files:58# pre-deploy them with proper filename, according to codepoint pattern59 60extract () {61 mkdir -p common62 63 for f in `ls *-flags/*.png`64 do e=${f##*/}65 e=${e%.png}66 if [ -n "$BASH_VERSION" ]67 then68 e=${e//-}69 e=${e//\'}70 #else filter them out by missing case below71 fi72 case $e in73 ??) # 1F1E6 1F1E8 ; RGI_Emoji_Flag_Sequence74 tagseq=false;;75 *) # 1F3F4 E0067 E0062 E0065 E006E E0067 E007F; RGI_Emoji_Tag_Sequence; flag: England76 tagseq=true;;77 esac78 if $tagseq79 then n=1f3f480 else n=81 fi82 # speed-up possible by using a common sed script...83 for l in $( echo "$e" | tr 'A-Z' 'a-z' | sed -e 's,.,& ,g' )84 do d=$( printf %d "'$l'" )85 if $tagseq86 then case "$l" in87 [a-z]|[0-9])88 d=$(( $d + 917504 ))89 n=$n-$( printf %x $d )90 ;;91 #[a-z]) d=$(( $d - 97 + 917601 )) # 'a' -> U+E0061 ...92 # n=$n-$( printf %x $d )93 # ;;94 #[0-9]) d=$(( $d - 48 + 917552 )) # '0' -> U+E0030 ...95 # n=$n-$( printf %x $d )96 # ;;97 esac98 else d=$(( $d - 97 + 127462 )) # U+1F1E699 n=$n-$( printf %x $d )100 fi101 done102 if $tagseq103 then n=$n-e007f.png104 else n=${n#-}.png105 fi106 107 echo "$f -> common/$n"108 if [ -L "$f" ]109 then # linking a symbolic link while renaming the target 110 # would yield a dangling link, so copy it111 cp "$f" "common/$n"112 else ln "$f" "common/$n"113 fi114 done115}116 117#############################################################################118# perform download and extraction/deployment119 120case "$1" in121""|-h|--help)122 echo "Usage: `basename $0` [-d | -e | -de]" >&2123 echo >&2124 echo "This script retrieves flag emojis from various sources." >&2125 echo >&2126 echo "Options:" >&2127 echo " -d Download flags emojis repositories" >&2128 echo " -n Download only Noto flags" >&2129 echo " -e Extract emoji files with proper filenames into common/" >&2130 echo " -de -d and -e" >&2131 echo " -ne -n and -e" >&2132 echo >&2133 if [ `uname` = "Linux" ] && type wslpath 2> /dev/null 1>&2134 then echo "Note: for direct deployment from WSL, first go into the common config directory:" >&2135 echo ' cd `wslpath "$APPDATA/mintty/emojis"` || cd `wslpath "$APPDATA/wsltty/emojis"`' >&2136 else echo "Note: for direct deployment, first go into subdirectory 'emojis' of one of the" >&2137 echo "mintty config directories:" >&2138 echo ' ~/.mintty' >&2139 echo ' ~/.config/mintty' >&2140 echo ' $APPDATA/mintty' >&2141 echo ' /usr/share/mintty' >&2142 fi143 exit;;144-n|--download-noto)145 download_noto146 ;;147-ne|--noto)148 download_noto149 extract150 ;;151-d|--download)152 download153 ;;154-e|--extract)155 extract156 ;;157-de|--all)158 download159 extract160 ;;161esac162 163#############################################################################164# end165 