1
0
Fork 0

Compare commits

..

No commits in common. "cc6b56e7a7196661bf290e027dcce119d321a063" and "392727e1694bf69521adc4178bf98cb0d9992f9d" have entirely different histories.

View file

@ -7,8 +7,7 @@
# Made with 💖 by dece. s/o to mon loulou, the bash samurai. License: WTFPLv2.
UCD_URL="https://www.unicode.org/Public/UCD/latest/ucdxml/ucd.all.flat.zip"
DIR="$HOME/.local/share/emoji"
LIST="$DIR/emojis.txt.gz"
UCD="$HOME/.local/share/emoji/ucd.all.flat.zip"
GREP="rg"
usage() {
@ -19,29 +18,22 @@ usage() {
echo " -l LIMIT limit number of output lines"
echo " -u unique result (equals -n and -l 1), no new line"
echo " -c show code point"
echo " -z use fzf mode"
echo " -d download UCD zip to create list file (requires curl)"
echo " -d download UCD zip (requires curl)"
}
[ $# -eq 0 ] && usage && exit
download_ucdxml() {
[ ! -d "$DIR" ] && mkdir -p "$DIR"
unc_list="${LIST%.gz}"
curl -L "$UCD_URL" | zcat | "$GREP" 'Emoji="Y"' | while read -r line; do
codepoint="$(echo "$line" | sed -E 's/.* cp="([0-9A-F]+)".*/\1/g')"
name="$(echo "$line" | sed -E 's/.* na="([^"]+)".*/\1/g')"
echo "$codepoint;$name" >> "$unc_list"
done
gzip "$unc_list"
directory="$(dirname "$UCD")"
[ ! -d "$directory" ] && mkdir -p "$directory"
curl -L -o "$UCD" "$UCD_URL"
}
HIDE_NAME=
LIMIT=
NO_NEW_LINE=
SHOW_CP=
FZF_MODE=
while getopts "hdnl:ucz" OPTION; do
while getopts "hdnl:uc" OPTION; do
case $OPTION in
h) usage; exit 0 ;;
d) download_ucdxml; exit $? ;;
@ -49,27 +41,28 @@ while getopts "hdnl:ucz" OPTION; do
l) LIMIT=$OPTARG ;;
u) HIDE_NAME=true; LIMIT=1; NO_NEW_LINE=true ;;
c) SHOW_CP=true ;;
z) FZF_MODE=true ;;
*) usage; exit 1 ;;
esac
done
shift $(( OPTIND - 1 ))
FILTER="$*"
if [ ! -f "$LIST" ]; then
echo "Can't find list file at $LIST. Use -d to download it!"
if [ ! -f "$UCD" ]; then
echo "Can't find UCD archive at $UCD. Use -d to download it!"
exit 1
fi
find_emojis() {
line_id=0
zcat "$LIST" | "$GREP" -i "$FILTER" | while read -r line; do
search_chars() {
zcat "$UCD" | "$GREP" 'Emoji="Y"' | "$GREP" -i "na.?=\"[^\"]*$1[^\"]*\""
}
line_id=0
search_chars "$FILTER" | while read -r line; do
[ -n "$LIMIT" ] && (( line_id >= LIMIT )) && break
readarray -d ";" -t elements <<< "$line"
codepoint="${elements[0]}"
codepoint="$(echo "$line" | sed -E 's/.* cp="([0-9A-F]+)".*/\1/g')"
result="$(echo -e "\\U$codepoint")"
if [ "$HIDE_NAME" != true ]; then
name="${elements[1]}"
name="$(echo "$line" | sed -E 's/.* na="([^"]+)".*/\1/g')"
result="$result $(echo "$name" | tr '[:upper:]' '[:lower:]')"
fi
if [ "$SHOW_CP" = true ]; then
@ -78,16 +71,4 @@ find_emojis() {
[ "$NO_NEW_LINE" = true ] && echo_opt="-n" || echo_opt=""
echo "$echo_opt" "$result"
line_id=$(( line_id + 1 ))
done
}
if [ "$FZF_MODE" = true ]; then
result="$(find_emojis | fzf)"
echo "$result"
if command -v xclip > /dev/null; then
echo -n "$(awk '{print $1}' <<< "$result")" | xclip
echo "(copied to X clipboard)"
fi
else
find_emojis
fi
done