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