Skip to content

Instantly share code, notes, and snippets.

@ericfreese
Last active September 25, 2020 22:34
Show Gist options
  • Save ericfreese/e6bb7260ec290ed91fde413b4eaa025d to your computer and use it in GitHub Desktop.
Save ericfreese/e6bb7260ec290ed91fde413b4eaa025d to your computer and use it in GitHub Desktop.
A kinda crappy swiss army knife for generating lines of emojis
#!/usr/bin/env zsh
program="${0:t}"
function usage() {
echo "usage: $program [--grep <pattern>] [--length <length>] [--sample <sample>] [--version <version>]" >&2
exit 1
}
function main() {
emulate -L zsh
setopt extendedglob
while (($#)); do
case $1 in
--grep) grep=$2; shift 2 || usage;;
--length) length=$2; shift 2 || usage;;
--sample) sample=$2; shift 2 || usage;;
--version) version=$2; shift 2 || usage;;
*) usage;;
esac
done
curl -s "https://unicode.org/Public/emoji/${version:-5.0}/emoji-test.txt" \
| grep '[^ ]' \
| while read line; do
case "$line" in
\#\ group:\ *) group="${line#\# group: }";;
\#\ subgroup:\ *) subgroup="${line#\# subgroup: }";;
*) echo "$line $group $subgroup";;
esac
done \
| grep 'fully-qualified' \
| () { if [[ -n "$grep" ]]; then grep -i "$grep"; else cat; fi } \
| shuf -rn ${sample:-1} \
| sed 's/ *;.*//' \
| while read line; do
code_points=(${(s: :)line})
code_points=$(for p in $code_points; do printf "\U$p"; done)
printf "$code_points%.0s" {1..${length:-20}}
done
}
main $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment