Jean-Tinland / simple-bar

A yabai status bar widget for Übersicht
https://www.jeantinland.com/toolbox/simple-bar
MIT License
1.21k stars 129 forks source link

Remove invisible U+200E unicode character from yabai query #406

Closed mrala closed 4 months ago

mrala commented 4 months ago

Description

If an app has an invisible U+200E character, it will not match the app name defined in app-icons.js.

Type of change

How Has This Been Tested?

❯ queryTitle=$(yabai -m query --windows --space 1 | jq '.[].app')
❯ echo $queryTitle
"‎WhatsApp"

# get the ASCII value of the unicode character
❯ echo $queryTitle | hexdump -C
00000000  22 e2 80 8e 57 68 61 74  73 41 70 70 22 0a        |"...WhatsApp".|
0000000e

# compare to expected string without unicode character
❯ echo \"WhatsApp\" | hexdump -C
00000000  22 57 68 61 74 73 41 70  70 22 0a                 |"WhatsApp".|
0000000b

❯ echo $queryTitle
"‎WhatsApp"

# get number of bytes with string that contains hidden unicode character
❯ echo $queryTitle | wc -c
      14

# remove UTF-8 hex (e2 80 8e)
❯ echo $queryTitle | sed "s/\xe2\x80\x8e//g" | wc -c
      11
# compare number of bytes to string without unicode character
❯ echo \"WhatsApp\" | wc -c
      11

# does not affect other unicode characters, test with Chinese name for Finder
❯ echo $'\U8BBF'$'\U8FBE'
访达
❯ echo $'\U8BBF'$'\U8FBE' | wc -c
       7
❯ echo $'\U8BBF'$'\U8FBE' | sed "s/\xe2\x80\x8e//g"
访达
❯ echo $'\U8BBF'$'\U8FBE' | sed "s/\xe2\x80\x8e//g" | wc -c
       7

Checklist:

Changes to make to the documentation

n/a

Jean-Tinland commented 4 months ago

Thank you for that! I appreciate your contributions :)