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,45 +41,34 @@ 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
[ -n "$LIMIT" ] && (( line_id >= LIMIT )) && break
readarray -d ";" -t elements <<< "$line"
codepoint="${elements[0]}"
result="$(echo -e "\\U$codepoint")"
if [ "$HIDE_NAME" != true ]; then
name="${elements[1]}"
result="$result $(echo "$name" | tr '[:upper:]' '[:lower:]')"
fi
if [ "$SHOW_CP" = true ]; then
result="$result (U+$codepoint)"
fi
[ "$NO_NEW_LINE" = true ] && echo_opt="-n" || echo_opt=""
echo "$echo_opt" "$result"
line_id=$(( line_id + 1 ))
done
} }
if [ "$FZF_MODE" = true ]; then line_id=0
result="$(find_emojis | fzf)" search_chars "$FILTER" | while read -r line; do
echo "$result" [ -n "$LIMIT" ] && (( line_id >= LIMIT )) && break
if command -v xclip > /dev/null; then codepoint="$(echo "$line" | sed -E 's/.* cp="([0-9A-F]+)".*/\1/g')"
echo -n "$(awk '{print $1}' <<< "$result")" | xclip result="$(echo -e "\\U$codepoint")"
echo "(copied to X clipboard)" if [ "$HIDE_NAME" != true ]; then
name="$(echo "$line" | sed -E 's/.* na="([^"]+)".*/\1/g')"
result="$result $(echo "$name" | tr '[:upper:]' '[:lower:]')"
fi fi
else if [ "$SHOW_CP" = true ]; then
find_emojis result="$result (U+$codepoint)"
fi fi
[ "$NO_NEW_LINE" = true ] && echo_opt="-n" || echo_opt=""
echo "$echo_opt" "$result"
line_id=$(( line_id + 1 ))
done