Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

1431 emoji environment variables for your echo'ing convenience

Jul
256
6
I wanted to have environment variables like %EMOJI_BROCCOLI% to use for emojis. For reasons.

I spent way too long programmatically generating these in python.

In the end, I created a file (emoji.env) that can be read with "set /r emoji.env" in about 0.7 seconds to grant access to about 1300 working emojis via environment variable.

This lets you echo emojis via environment variables, like so:

1689021401719.png



The file looks like this:
Code:
EMOJI_BICYCLE=%@CHAR[55357]%@CHAR[57010]
EMOJI_BIKINI=%@CHAR[55357]%@CHAR[56409]
EMOJI_BILLED_CAP=%@CHAR[55358]%@CHAR[56802]
EMOJI_BIOHAZARD=%@CHAR[9763]%@CHAR[65039]
EMOJI_BIRD=%@CHAR[55357]%@CHAR[56358]
EMOJI_BIRTHDAY_CAKE=%@CHAR[55356]%@CHAR[57218]
EMOJI_BISON=%@CHAR[55358]%@CHAR[56748]
EMOJI_BITING_LIP=%@CHAR[55358]%@CHAR[57062]
EMOJI_BLACK_CAT=%@CHAR[55357]%@CHAR[56328]
EMOJI_BLACK_CIRCLE=%@CHAR[9899]%@CHAR[0]
EMOJI_BLACK_HEART=%@CHAR[55357]%@CHAR[56740]
EMOJI_BLACK_LARGE_SQUARE=%@CHAR[11035]%@CHAR[0]

And gives you environment variables like this:

1689020971164.png


It's not very tested, but they mostly work, some empty boxes but it looks like >90% work:
1689021020487.png




I hit quite a few brick walls trying to generate a better list. This one is flawed. I would love if someone could make my code even better:

Code:
import emoji
def create_script_to_define_emoji_characters(): #2860, 1431 unique
    print("EMOJI_ENVIRONMENT_VARIABLES_CREATED_BY=fix_unicode_files.py script")
    import ctypes
    from emoji.unicode_codes import EMOJI_DATA
    processed_emojis = set()  # Set to track processed emojis
    rights = set()  # Set to track right half of = in output file so we don't make duplicates
    output_strings = set()  # Set to handle duplicate output strings
    for emoji, emoji_data in EMOJI_DATA.items():
        # Fetch the base emoji without any skin tone variation
        base_emoji = emoji.split('\u200d')[0]

        emoji_name_meat = emoji_data['en'].upper().replace(' ', '_').replace(':', '').replace('-', '_').replace("'", '').replace('SKIN_TONE', 'SKIN').replace('&', '_AND_')

        # Construct the fully qualified and unqualified names
        fully_qualified_name = f"EMOJI_{emoji_name_meat}"
        unqualified_name = f"EMOJI_{emoji_name_meat}_UNQUALIFIED"

        # Determine the name to be used based on the status of the emoji
        if emoji_data['status'] == 3:           #rem emoji.fully_qualified:component = 1 fully_qualified = 2 minimally_qualified = 3 unqualified = 4
            emoji_name = unqualified_name
        else:
            emoji_name = fully_qualified_name

        # Check if the current version of this emoji has already been processed
        if emoji_name in processed_emojis:
            continue
        processed_emojis.add(emoji_name)

        # Convert the emoji into a ctypes wide string
        # Then cast it to a pointer to short (16-bit) integers, and fetch the values
        emoji_code_units = ctypes.cast(ctypes.c_wchar_p(emoji), ctypes.POINTER(ctypes.c_uint16))

        # Create the output string
        right = ""
        for i in range(2):  # two UTF-16 code units
            right += f"%@CHAR[{emoji_code_units}]"

        if right in rights:
            continue
        rights.add(right)

        output_string = f"{emoji_name}={right}"

        output_strings.add(output_string)  # Add to a set to handle duplicates

    # Print the output strings
    printed = set()
    for output_string in output_strings:
        if output_string in printed: continue
        printed.add(output_string)
        print(output_string)


'''
 
Last edited:
I'd love for this to work better, as the emoji python package updates with each new release of emojis, which would make it possible to regenerate this as new emojis come out.

But my output file is FULL OF DUPES despite me putting lots of code in to stop that. I don't get it.

So ultimately I had to pass my output through |sort and |uniq to get an actual unique list

And scrap the whole separating fully_qualified from unqualified. (Now, I'm not even sure which one makes it to the environment when there are 2 emoji of the same name. Ugh. Yuck)

Stuff is missing. Stuff is definitely broken. Not sure who's fault. Probably mine.

But for the most part, lots of extra stuff here. It's nice to be able to grep your environment to find a suitable emoji for a script's situation, and then to use it in a way that won't decay from file encoding issues. (I've had problems with emoji decaying into other encodings when dealing with scripts that have emoji directly embedded into them. Even git didn't save me. I've lost hours of work because of this. So now I'm wary and want environment variables.)
 
I also made an emoji-search.bat which takes a regular expression and returns all the emojis matching it. If you use my set-colors.bat which sets BIG_TOP and BIG_BOT ansi codes to use double-height text, it will also display the emoji double height
1689330957419.png



Code:
@Echo off

::::: PURPOSE:  To echo all eoji variables representing a regular expression we provide


REM parameter processing
        set PARAM=%1
        set SILENT=0
        if "%PARAM%" eq  ""  (set PARAM=.*)
        if  "silent" eq "%1" (set SILENT=1)


REM dump environment to file
        if not defined TMPFILE (call settmpfile)
        if not exist %TMPFILE% .or. "%2" eq "force" (
            call important "Dumping environment variables..."
            set|sed "s/=.*$//ig" >"%TMPFILE%"
            :DEBUG: (set|sed "s/=.*$//ig") %+ echo TMPFILE: %+ type "%TMPFILE%" %+ pause
        )

REM go through each enviroment variable
        for /f "tokens=1-999" %co in (%TMPFILE%) gosub ProcessEnvVar %co%


goto :END
    :ProcessEnvVar [var]
        if          "%@REGEX[EMOJI_,%@UPPER[%VAR%]]" ne "1" (return)
        if "%@REGEX[%@UPPER[%PARAM],%@UPPER[%VAR%]]" ne "1" (return)
        if %FOUND ne 1 (echo.)
        set FOUND=1
        if %SILENT ne 1 (
            echo  %faint%* This is%faint_off% %VAR%: %[%VAR%]
            REM also echo it in double-height if we can:
                if defined BIG_TOP .and. defined BIG_BOT (
                    echo   %BIG_TOP%%[%VAR%]
                    echo   %BIG_BOT%%[%VAR%]
                )
            echo.
        )
    return
:END
 

Attachments

  • emoji-search.bat
    1.3 KB · Views: 92
  • set-colors.bat
    17.9 KB · Views: 94
  • settmpfile.bat
    645 bytes · Views: 92
Last edited:
Hi, thanks for sharing, it’s really interesting!



I've been slowly adding color, emoji, ANSI stylings, to my old BAT files, to basically prepare myself for alzheimer's/elderlyness and add as much assistance as possible to my own workings so that I can comprehend wtf is going on, haha.
 
Back
Top