Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
getemojis239 linesDownload Raw Back to bin
1#! /bin/bash2 3trace () {4#	echo $* >&25	true6}7 8wgetfirst=false9#wgetfirst=true10 11case "$1" in12-sh)	postproc=cat13	shift;;14*)	postproc=bash;;15esac16 17case `basename "$PWD"` in18mintty)19	echo "You seem to be in a mintty config directory:" >&220	echo "	$PWD" >&221	echo "For direct emoji deployment, run this script from its subdirectory 'emojis'." >&222	exit;;23esac24 25emojisurl0=https://www.unicode.org/emoji/charts/full-emoji-list.html26emojisurl1=https://www.unicode.org/emoji/charts/full-emoji-modifiers.html27 28download () {29	if $wgetfirst30	then	wget -N -t 1 "$1"31	elif type curl32	then	# prefer curl because it works better behind proxies33		if [ -f `basename "$1"` ]34		then	curl -RO -z `basename "$1"` "$1"35		else	# avoid "Warning: Illegal date format for -z"36			curl -RO "$1"37		fi38	else	wget -N -t 1 "$1"39	fi ||40	(echo "FILE: $1" >&241	 echo "ERROR: download failed, file incomplete" >&242	 if [ -f `basename "$1"` ]43	 then	# enforce fresh download next time44		touch -d 1970-01-01 `basename "$1"`45	 fi46	 return 947	)48}49 50case "$1" in51""|-h|--help)52	echo "Usage: `basename $0` [-d | DIR | .../full-emoji-list.html] [EMOJI_STYLE]..." >&253	echo >&254	echo "This script extracts emojis graphics (.png format) from a downloaded copy of" >&255	echo "	$emojisurl0" >&256	echo "	$emojisurl1" >&257	echo "for the selected emoji style sets, or (if none selected) all of them:" >&258	echo "	google" >&259	echo "and always extracts common emoji graphics." >&260	echo "Other styles are no longer provided at unicode.org:" >&261	echo "	[apple facebook windows twitter emojione samsung]" >&262	echo >&263	echo "Options:" >&264	echo "	-d	Download the chart files" >&265	echo "	DIR	Expect the chart files in given directory" >&266	echo >&267	echo "Warning: with all styles selected, this may take a while." >&268	echo >&269	if [ `uname` = "Linux" ] && type wslpath 2> /dev/null 1>&270	then	echo "Note: for direct deployment from WSL, first go into the common config directory:" >&271		echo '  cd `wslpath "$APPDATA/mintty/emojis"` || cd `wslpath "$APPDATA/wsltty/emojis"`' >&272	else	echo "Note: for direct deployment, first go into subdirectory 'emojis' of one of the" >&273		echo "mintty config directories:" >&274		echo '  ~/.mintty' >&275		echo '  ~/.config/mintty' >&276		echo '  $APPDATA/mintty' >&277		echo '  /usr/share/mintty' >&278	fi79	exit;;80-d|--download)81	if download $emojisurl0 && download $emojisurl182	then	emojis0=full-emoji-list.html83		emojis1=full-emoji-modifiers.html84	else	echo Download failed >&285		exit86	fi87	shift;;88*.html)	emojis1=`dirname "$1"`/full-emoji-modifiers.html89	if [ -r "$1" -a -r "$emojis1" ]90	then	emojis0="$1"91	else	echo Not readable: "$1" "$emojis1" >&292		exit93	fi94	shift;;95*)	if [ -d "$1" ]96	then	emojis0="$1"/full-emoji-list.html97		emojis1="$1"/full-emoji-modifiers.html98		if [ -r "$emojis0" -a -r "$emojis1" ]99		then	true100		else	echo Not readable: "$emojis0" "$emojis1" >&2101			exit102		fi103		shift104	else	echo Missing file name of full emoji list >&2105		exit106	fi;;107esac108 109echo -n "Using " >&2110cat "$emojis0" | sed -e "s,<title>\(.*\)</title>,\1," -e t -e d >&2111 112#cat "$emojis0" |113#sed -e "/^<\/tr/ q" -e "s/.*<th.*#col-vendor.>\([^.<]*\).*/\1/" -e t -e d |114#pr -t -n | sed -e "s,^,vendor ," -e 7q115# 11.0:116#	vendor     1    Appl117#	vendor     2    Goog118#	vendor     3    Twtr119#	vendor     4    One120#	vendor     5    FB121#	vendor     6    Sams122#	vendor     7    Wind123# 12.0:124#	vendor     1    Appl125#	vendor     2    Goog126#	vendor     3    FB127#	vendor     4    Wind128#	vendor     5    Twtr129#	vendor     6    Joy130#	vendor     7    Sams131 132seli=0133styles=(common)134for vendor in `cat "$emojis0" |135  sed -e "/^<\/tr/ q" -e "s/.*<th.*#col-vendor.>\([^.<]*\).*/\1/" -e t -e d |136  sed -e 7q`137do	seli=`expr $seli + 1`138	case "$vendor" in139	Appl)	st=apple; apple=$seli;;140	Sample|Goog)	st=google; google=$seli;;141	FB)	st=facebook; facebook=$seli;;142	Wind)	st=windows; windows=$seli;;143	Twtr)	st=twitter; twitter=$seli;;144	One|Joy) st=emojione; emojione=$seli;;145	Sams)	st=samsung; samsung=$seli;;146	esac147	styles[$seli]=$st148done149 150case "$1" in151"")	#set - apple google facebook windows twitter emojione samsung152	set - google153	;;154esac155sel=156while	case "$1" in157	apple)		seli="$apple";;158	google)		seli="$google";;159	facebook)	seli="$facebook";;160	windows)	seli="$windows";;161	twitter)	seli="$twitter";;162	joy|emojione)	seli="$emojione";;163	samsung)	seli="$samsung";;164	"")	false;;165	*)	echo emoji set "$1" not known; exit;;166	esac167do	sel="$sel$seli"168	mkdir -p "$1"169	shift170done171mkdir -p common google172 173export sel174 175echo "Warning: this may take a while on Cygwin" >&2176 177LC_ALL=C178export LC_ALL179 180total=`grep -e "name='\([^']*\)'.*U+" "$emojis0" "$emojis1" | wc -l`181export total182 183(184echo "Extracting $total emojis " >&2185 186echo LC_ALL=C187echo export LC_ALL188echo total=$total189echo sel=$sel190echo "styles=(${styles[*]})"191 192cat <<\/EOS193n=0194 195name () {196  ename=$1197  style=0198  n=$(( $n + 1 ))199  p=$(( ${n}00 / $total ))200  echo "emoji $ename (${p}%)" >&2201}202 203img0 () {204  echo " common $ename.png" >&2205  echo "$1" | base64 -d > common/$ename.png206}207 208imgg () {209  echo " google $ename.png" >&2210  echo "$1" | base64 -d > google/$ename.png211}212 213img () {214  style=$(( $style + 1 ))215  case $sel in216  *$style*)	echo "$1" | base64 -d > ${styles[$style]}/$ename.png;;217  esac218}219 220imgskip () {221  style=$(( $style + 1 ))222  case $sel in223  *$style*)	echo " skip ${styles[$style]}/$ename.png" >&2;;224  esac225}226 227/EOS228 229cat "$emojis0" "$emojis1" |230sed -e "s/^.*name='\([^']*\)'.*U+.*/name \1/" -e "t name" \231    -e "s/.*—.*/imgskip/" -e t \232    -e "s@^.*….*src='data:image/png;base64,\([^']*\)'.*src='data:image/png;base64,\([^']*\)'.*@imgg \1\nimg0 \2@" -e t \233    -e "s@^.*….*src='data:image/png;base64,\([^']*\)'.*@img0 \1@" -e t \234    -e "s@^.*src='data:image/png;base64,\([^']*\)'.*@img \1@" -e t \235    -e d \236    -e ": name" \237    -e "s,_,-,g"238) | $postproc239 
codekingpro/portable-devtools · Team Ai