emoji.plugin.zsh 7.0 KB

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