emoji.plugin.zsh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. # emoji plugin
  2. #
  3. # Makes emoji support available within ZSH
  4. #
  5. # See the README for documentation.
  6. _omz_emoji_plugin_dir="${0:h}"
  7. () {
  8. local LC_ALL=en_US.UTF-8
  9. typeset -gAH emoji_groups
  10. typeset -gAH emoji_con
  11. typeset -gAH emoji2
  12. typeset -gAH emoji_skintone
  13. source "$_omz_emoji_plugin_dir/emoji-char-definitions.zsh"
  14. unset _omz_emoji_plugin_dir
  15. # These additional emoji are not in the definition file, but are useful in conjunction with it
  16. # This is a combinin character that can be placed after any other character to surround
  17. # it in a "keycap" symbol.
  18. # The digits 0-9 are already in the emoji table as keycap_digit_<N>, keycap_ten, etc.
  19. # It's unclear whether this should be in the $emoji array, because those characters are all ones
  20. # which can be displayed on their own.
  21. #emoji[combining_enclosing_keycap]="\U20E3"
  22. emoji[regional_indicator_symbol_letter_d_regional_indicator_symbol_letter_e]=$'\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA'
  23. emoji[regional_indicator_symbol_letter_g_regional_indicator_symbol_letter_b]=$'\xF0\x9F\x87\xAC\xF0\x9F\x87\xA7'
  24. emoji[regional_indicator_symbol_letter_c_regional_indicator_symbol_letter_n]=$'\xF0\x9F\x87\xA8\xF0\x9F\x87\xB3'
  25. emoji[regional_indicator_symbol_letter_j_regional_indicator_symbol_letter_p]=$'\xF0\x9F\x87\xAF\xF0\x9F\x87\xB5'
  26. emoji[regional_indicator_symbol_letter_k_regional_indicator_symbol_letter_r]=$'\xF0\x9F\x87\xB0\xF0\x9F\x87\xB7'
  27. emoji[regional_indicator_symbol_letter_f_regional_indicator_symbol_letter_r]=$'\xF0\x9F\x87\xAB\xF0\x9F\x87\xB7'
  28. emoji[regional_indicator_symbol_letter_e_regional_indicator_symbol_letter_s]=$'\xF0\x9F\x87\xAA\xF0\x9F\x87\xB8'
  29. emoji[regional_indicator_symbol_letter_i_regional_indicator_symbol_letter_t]=$'\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9'
  30. emoji[regional_indicator_symbol_letter_u_regional_indicator_symbol_letter_s]=$'\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8'
  31. emoji[regional_indicator_symbol_letter_r_regional_indicator_symbol_letter_u]=$'\xF0\x9F\x87\xB7\xF0\x9F\x87\xBA'
  32. # Nonstandard alias names
  33. emoji[vulcan_salute]=$'\U1F596'
  34. # Emoji combining and auxiliary characters
  35. # "Variation Selectors" for controlling text vs emoji style presentation
  36. # These apply to the immediately preceding character
  37. emoji2[text_style]=$'\UFE0E'
  38. emoji2[emoji_style]=$'\UFE0F'
  39. # Joiner that indicates a single combined-form glyph (ligature) should be used
  40. emoji2[zero_width_joiner]=$'\U200D'
  41. # Skin tone modifiers
  42. emoji2[emoji_modifier_fitzpatrick_type_1_2]=$'\U1F3FB'
  43. emoji2[emoji_modifier_fitzpatrick_type_3]=$'\U1F3FC'
  44. emoji2[emoji_modifier_fitzpatrick_type_4]=$'\U1F3FD'
  45. emoji2[emoji_modifier_fitzpatrick_type_5]=$'\U1F3FE'
  46. emoji2[emoji_modifier_fitzpatrick_type_6]=$'\U1F3FF'
  47. # Various other combining characters. (Incomplete list; I selected ones that sound useful)
  48. emoji2[combining_enclosing_circle]=$'\U20DD'
  49. emoji2[combining_enclosing_square]=$'\U20DE'
  50. emoji2[combining_enclosing_diamond]=$'\U20DF'
  51. emoji2[combining_enclosing_circle_backslash]=$'\U20E0'
  52. emoji2[combining_enclosing_screen]=$'\U20E2'
  53. emoji2[combining_enclosing_keycap]=$'\U20E3'
  54. emoji2[combining_enclosing_upward_pointing_triangle]=$'\U20E4'
  55. # Easier access to skin tone modifiers
  56. emoji_skintone[1_2]=$'\U1F3FB'
  57. emoji_skintone[3]=$'\U1F3FC'
  58. emoji_skintone[4]=$'\U1F3FD'
  59. emoji_skintone[5]=$'\U1F3FE'
  60. emoji_skintone[6]=$'\U1F3FF'
  61. # Emoji groups
  62. # These are stored in a single associative array, $emoji_groups, to avoid cluttering up the global
  63. # namespace, and to allow adding additional group definitions at run time.
  64. # The keys are the group names, and the values are whitespace-separated lists of emoji character names.
  65. #
  66. # These extra local arrays are used to allow more convenient formatting of the source code.
  67. emoji_groups[fruits]="
  68. tomato
  69. aubergine
  70. grapes
  71. melon
  72. watermelon
  73. tangerine
  74. banana
  75. pineapple
  76. red_apple
  77. green_apple
  78. peach
  79. cherries
  80. strawberry
  81. lemon
  82. pear
  83. "
  84. emoji_groups[vehicles]="
  85. airplane
  86. rocket
  87. railway_car
  88. high_speed_train
  89. high_speed_train_with_bullet_nose
  90. bus
  91. ambulance
  92. fire_engine
  93. police_car
  94. taxi
  95. automobile
  96. recreational_vehicle
  97. delivery_truck
  98. ship
  99. speedboat
  100. bicycle
  101. helicopter
  102. steam_locomotive
  103. train
  104. light_rail
  105. tram
  106. oncoming_bus
  107. trolleybus
  108. minibus
  109. oncoming_police_car
  110. oncoming_taxi
  111. oncoming_automobile
  112. articulated_lorry
  113. tractor
  114. monorail
  115. mountain_railway
  116. suspension_railway
  117. mountain_cableway
  118. aerial_tramway
  119. rowboat
  120. bicyclist
  121. mountain_bicyclist
  122. sailboat
  123. "
  124. emoji_groups[animals]="
  125. snail
  126. snake
  127. horse
  128. sheep
  129. monkey
  130. chicken
  131. boar
  132. elephant
  133. octopus
  134. spiral_shell
  135. bug
  136. ant
  137. honeybee
  138. lady_beetle
  139. fish
  140. tropical_fish
  141. blowfish
  142. turtle
  143. hatching_chick
  144. baby_chick
  145. front_facing_baby_chick
  146. bird
  147. penguin
  148. koala
  149. poodle
  150. bactrian_camel
  151. dolphin
  152. mouse_face
  153. cow_face
  154. tiger_face
  155. rabbit_face
  156. cat_face
  157. dragon_face
  158. spouting_whale
  159. horse_face
  160. monkey_face
  161. dog_face
  162. pig_face
  163. frog_face
  164. hamster_face
  165. wolf_face
  166. bear_face
  167. panda_face
  168. rat
  169. mouse
  170. ox
  171. water_buffalo
  172. cow
  173. tiger
  174. leopard
  175. rabbit
  176. cat
  177. dragon
  178. crocodile
  179. whale
  180. ram
  181. goat
  182. rooster
  183. dog
  184. pig
  185. dromedary_camel
  186. "
  187. emoji_groups[faces]="
  188. grinning_face_with_smiling_eyes
  189. face_with_tears_of_joy
  190. smiling_face_with_open_mouth
  191. smiling_face_with_open_mouth_and_smiling_eyes
  192. smiling_face_with_open_mouth_and_cold_sweat
  193. smiling_face_with_open_mouth_and_tightly_closed_eyes
  194. winking_face
  195. smiling_face_with_smiling_eyes
  196. face_savouring_delicious_food
  197. relieved_face
  198. smiling_face_with_heart_shaped_eyes
  199. smirking_face
  200. unamused_face
  201. face_with_cold_sweat
  202. pensive_face
  203. confounded_face
  204. face_throwing_a_kiss
  205. kissing_face_with_closed_eyes
  206. face_with_stuck_out_tongue_and_winking_eye
  207. face_with_stuck_out_tongue_and_tightly_closed_eyes
  208. disappointed_face
  209. angry_face
  210. pouting_face
  211. crying_face
  212. persevering_face
  213. face_with_look_of_triumph
  214. disappointed_but_relieved_face
  215. fearful_face
  216. weary_face
  217. sleepy_face
  218. tired_face
  219. loudly_crying_face
  220. face_with_open_mouth_and_cold_sweat
  221. face_screaming_in_fear
  222. astonished_face
  223. flushed_face
  224. dizzy_face
  225. face_with_medical_mask
  226. "
  227. }
  228. # Prints a random emoji character
  229. #
  230. # random_emoji [group]
  231. #
  232. function random_emoji() {
  233. local group=$1
  234. local names
  235. if [[ -z "$group" || "$group" == "all" ]]; then
  236. names=(${(k)emoji})
  237. else
  238. names=(${=emoji_groups[$group_name]})
  239. fi
  240. local list_size=$#names
  241. local random_index=$(( ( RANDOM % $list_size ) + 1 ))
  242. local name=${names[$random_index]}
  243. echo ${emoji[$name]}
  244. }
  245. # Displays a listing of emoji with their names
  246. #
  247. # display_emoji [group]
  248. #
  249. function display_emoji() {
  250. local group=$1
  251. local names
  252. if [[ -z "$group" || "$group" == "all" ]]; then
  253. names=(${(k)emoji})
  254. else
  255. names=(${=emoji_groups[$group]})
  256. fi
  257. # The extra spaces in output here are a hack for readability, since some
  258. # terminals treat these emoji chars as single-width.
  259. for i in $names; do
  260. printf '%s ' "$emoji[$i]"
  261. done
  262. print
  263. for i in $names; do
  264. echo "${emoji[$i]} = $i"
  265. done
  266. }