summaryrefslogtreecommitdiff
path: root/ar/.local/bin/emojiupdate
blob: 861c9b0c189e101fa3a6ec687a0fcc11202c7b81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh

##
## For fontawesome icons update, run the command block in terminal.
##
# curl -sSL -o icons_raw.json "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/metadata/icons.json" &&
# jq -r 'to_entries[] | select(.value.unicode) | .value.unicode + " " + .key' "icons_raw.json" |
# while read -r hex name; do
#   hex_uc=$(printf '%s' "$hex" | tr '[:lower:]' '[:upper:]')
#   if [ "${#hex_uc}" -le 4 ]; then
#     unicode="\\u$hex_uc"
#   else
#     unicode="\\U$(printf '%08X' "0x$hex_uc")"
#   fi
#
#   printf "%b  %s; %s\n" "$unicode" "$name" "$hex"
# done > "${XDG_DOTFILES_DIR:-$HOME/.dotfiles}/global/.local/share/thesiah/chars/icons"

# Define input and output files
URL="https://unicode.org/Public/emoji/latest/emoji-test.txt"
INPUT_FILE="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/global/.local/share/thesiah/chars/emoji_raw"
TEMP_FILE="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/global/.local/share/thesiah/chars/emoji_temp"
OUTPUT_FILE="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/global/.local/share/thesiah/chars/emoji"

# Create the directory for output files if it doesn't exist
mkdir -p "$(dirname "$INPUT_FILE")"

# Download the emoji file
echo "Downloading emoji-test.txt from Unicode..."
if curl -o "$INPUT_FILE" -L "$URL"; then
  echo "Download complete! File saved to: $INPUT_FILE"
else
  echo "Failed to download emoji"
  exit 1
fi

awk '
    # Skip empty lines and comments
    /^[[:space:]]*$/ || /^#/ { next }

    # Keep only fully-qualified lines
    !/(fully-qualified|component)/ { next }

    # Skip lines containing 200D (zero-width joiner)
    /200D/ { next }

    # Skip lines containing components
    $2 ~ /1F3F[BCDEF]/ { next }

    # Print valid lines
    { print }
' "$INPUT_FILE" >"$TEMP_FILE"

# Second stage: Extract emoji and description
awk -F'#' '
    {
        if (NF >= 2) {
            full_data = $2                                # Extract the emoji and description (after #)
            gsub(/^[[:space:]]+|[[:space:]]+$/, "", full_data)  # Trim spaces around the entire field

            split(full_data, parts, " ")                  # Split into parts by spaces
            emoji = parts[1]                              # First part is the emoji

            # Reconstruct description from parts[3] onward
            description = ""
            for (i = 3; i <= length(parts); i++) {
                description = description parts[i] " "
            }

            # Remove excessive internal spaces and trim description
            gsub(/[[:space:]]+/, " ", description)
            gsub(/^[[:space:]]+|[[:space:]]+$/, "", description)

            # Print emoji and description
            print emoji, description
        }
    }
' "$TEMP_FILE" >"$OUTPUT_FILE"

rm -rf "$INPUT_FILE" "$TEMP_FILE"
echo "Processing complete! File saved to: $OUTPUT_FILE"