emoji.plugin.zsh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. emoji_groups[fruits]="
  66. tomato
  67. aubergine
  68. grapes
  69. melon
  70. watermelon
  71. tangerine
  72. banana
  73. pineapple
  74. red_apple
  75. green_apple
  76. peach
  77. cherries
  78. strawberry
  79. lemon
  80. pear
  81. "
  82. emoji_groups[vehicles]="
  83. airplane
  84. rocket
  85. railway_car
  86. high_speed_train
  87. high_speed_train_with_bullet_nose
  88. bus
  89. ambulance
  90. fire_engine
  91. police_car
  92. taxi
  93. automobile
  94. recreational_vehicle
  95. delivery_truck
  96. ship
  97. speedboat
  98. bicycle
  99. helicopter
  100. steam_locomotive
  101. train
  102. light_rail
  103. tram
  104. oncoming_bus
  105. trolleybus
  106. minibus
  107. oncoming_police_car
  108. oncoming_taxi
  109. oncoming_automobile
  110. articulated_lorry
  111. tractor
  112. monorail
  113. mountain_railway
  114. suspension_railway
  115. mountain_cableway
  116. aerial_tramway
  117. rowboat
  118. bicyclist
  119. mountain_bicyclist
  120. sailboat
  121. "
  122. emoji_groups[animals]="
  123. snail
  124. snake
  125. horse
  126. sheep
  127. monkey
  128. chicken
  129. boar
  130. elephant
  131. octopus
  132. spiral_shell
  133. bug
  134. ant
  135. honeybee
  136. lady_beetle
  137. fish
  138. tropical_fish
  139. blowfish
  140. turtle
  141. hatching_chick
  142. baby_chick
  143. front_facing_baby_chick
  144. bird
  145. penguin
  146. koala
  147. poodle
  148. bactrian_camel
  149. dolphin
  150. mouse_face
  151. cow_face
  152. tiger_face
  153. rabbit_face
  154. cat_face
  155. dragon_face
  156. spouting_whale
  157. horse_face
  158. monkey_face
  159. dog_face
  160. pig_face
  161. frog_face
  162. hamster_face
  163. wolf_face
  164. bear_face
  165. panda_face
  166. rat
  167. mouse
  168. ox
  169. water_buffalo
  170. cow
  171. tiger
  172. leopard
  173. rabbit
  174. cat
  175. dragon
  176. crocodile
  177. whale
  178. ram
  179. goat
  180. rooster
  181. dog
  182. pig
  183. dromedary_camel
  184. "
  185. emoji_groups[faces]="
  186. grinning_face_with_smiling_eyes
  187. face_with_tears_of_joy
  188. smiling_face_with_open_mouth
  189. smiling_face_with_open_mouth_and_smiling_eyes
  190. smiling_face_with_open_mouth_and_cold_sweat
  191. smiling_face_with_open_mouth_and_tightly_closed_eyes
  192. winking_face
  193. smiling_face_with_smiling_eyes
  194. face_savouring_delicious_food
  195. relieved_face
  196. smiling_face_with_heart_shaped_eyes
  197. smirking_face
  198. unamused_face
  199. face_with_cold_sweat
  200. pensive_face
  201. confounded_face
  202. face_throwing_a_kiss
  203. kissing_face_with_closed_eyes
  204. face_with_stuck_out_tongue_and_winking_eye
  205. face_with_stuck_out_tongue_and_tightly_closed_eyes
  206. disappointed_face
  207. angry_face
  208. pouting_face
  209. crying_face
  210. persevering_face
  211. face_with_look_of_triumph
  212. disappointed_but_relieved_face
  213. fearful_face
  214. weary_face
  215. sleepy_face
  216. tired_face
  217. loudly_crying_face
  218. face_with_open_mouth_and_cold_sweat
  219. face_screaming_in_fear
  220. astonished_face
  221. flushed_face
  222. dizzy_face
  223. face_with_medical_mask
  224. "
  225. }
  226. # Prints a random emoji character
  227. #
  228. # random_emoji [group]
  229. #
  230. function random_emoji() {
  231. local group=$1
  232. local names
  233. if [[ -z "$group" || "$group" == "all" ]]; then
  234. names=(${(k)emoji})
  235. else
  236. names=(${=emoji_groups[$group]})
  237. fi
  238. local list_size=${#names}
  239. [[ $list_size -eq 0 ]] && return 1
  240. local random_index=$(( ( RANDOM % $list_size ) + 1 ))
  241. local name=${names[$random_index]}
  242. echo ${emoji[$name]}
  243. }
  244. # Displays a listing of emoji with their names
  245. #
  246. # display_emoji [group]
  247. #
  248. function display_emoji() {
  249. local group=$1
  250. local names
  251. if [[ -z "$group" || "$group" == "all" ]]; then
  252. names=(${(k)emoji})
  253. else
  254. names=(${=emoji_groups[$group]})
  255. fi
  256. # The extra spaces in output here are a hack for readability, since some
  257. # terminals treat these emoji chars as single-width.
  258. for i in $names; do
  259. printf '%s ' "$emoji[$i]"
  260. done
  261. print
  262. for i in $names; do
  263. echo "${emoji[$i]} = $i"
  264. done
  265. }