]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/emoji/emoji.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / emoji / emoji.plugin.zsh
1 # emoji plugin
2 #
3 # Makes emoji support available within ZSH
4 #
5 # See the README for documentation.
6
7 # Handle $0 according to the standard:
8 # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
9 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
10 0="${${(M)0:#/*}:-$PWD/$0}"
11
12 _omz_emoji_plugin_dir="${0:h}"
13
14 () {
15
16 local LC_ALL=en_US.UTF-8
17
18 typeset -gAH emoji_skintone
19
20 source "$_omz_emoji_plugin_dir/emoji-char-definitions.zsh"
21 unset _omz_emoji_plugin_dir
22
23 # These additional emoji are not in the definition file, but are useful in conjunction with it
24
25 # This is a combining character that can be placed after any other character to surround
26 # it in a "keycap" symbol.
27 # The digits 0-9 are already in the emoji table as keycap_digit_<N>, keycap_ten, etc. 
28 # It's unclear whether this should be in the $emoji array, because those characters are all ones
29 # which can be displayed on their own.
30
31 emoji[regional_indicator_symbol_letter_d_regional_indicator_symbol_letter_e]=$'\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA'
32 emoji[regional_indicator_symbol_letter_g_regional_indicator_symbol_letter_b]=$'\xF0\x9F\x87\xAC\xF0\x9F\x87\xA7'
33 emoji[regional_indicator_symbol_letter_c_regional_indicator_symbol_letter_n]=$'\xF0\x9F\x87\xA8\xF0\x9F\x87\xB3'
34 emoji[regional_indicator_symbol_letter_j_regional_indicator_symbol_letter_p]=$'\xF0\x9F\x87\xAF\xF0\x9F\x87\xB5'
35 emoji[regional_indicator_symbol_letter_k_regional_indicator_symbol_letter_r]=$'\xF0\x9F\x87\xB0\xF0\x9F\x87\xB7'
36 emoji[regional_indicator_symbol_letter_f_regional_indicator_symbol_letter_r]=$'\xF0\x9F\x87\xAB\xF0\x9F\x87\xB7'
37 emoji[regional_indicator_symbol_letter_e_regional_indicator_symbol_letter_s]=$'\xF0\x9F\x87\xAA\xF0\x9F\x87\xB8'
38 emoji[regional_indicator_symbol_letter_i_regional_indicator_symbol_letter_t]=$'\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9'
39 emoji[regional_indicator_symbol_letter_u_regional_indicator_symbol_letter_s]=$'\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8'
40 emoji[regional_indicator_symbol_letter_r_regional_indicator_symbol_letter_u]=$'\xF0\x9F\x87\xB7\xF0\x9F\x87\xBA'
41
42 # Easier access to skin tone modifiers
43 emoji_skintone[1_2]=$'\U1F3FB'
44 emoji_skintone[3]=$'\U1F3FC'
45 emoji_skintone[4]=$'\U1F3FD'
46 emoji_skintone[5]=$'\U1F3FE'
47 emoji_skintone[6]=$'\U1F3FF'
48 }
49
50 # Prints a random emoji character
51 #
52 #  random_emoji [group]
53 #
54 function random_emoji() {
55   local group=$1
56   local names
57   if [[ -z "$group" || "$group" == "all" ]]; then
58         names=(${(k)emoji})
59   else
60         names=(${=emoji_groups[$group]})
61   fi
62   local list_size=${#names}
63   [[ $list_size -eq 0 ]] && return 1
64   local random_index=$(( ( RANDOM % $list_size ) + 1 ))
65   local name=${names[$random_index]}
66   if [[ "$group" == "flags" ]]; then 
67     echo ${emoji_flags[$name]}
68   else 
69     echo ${emoji[$name]}
70   fi
71 }
72
73 # Displays a listing of emoji with their names
74 #
75 # display_emoji [group]
76 #
77 function display_emoji() {
78   local group=$1
79   local names
80   if [[ -z "$group" || "$group" == "all" ]]; then
81         names=(${(k)emoji})
82   else
83     names=(${=emoji_groups[$group]})
84   fi
85   # The extra spaces in output here are a hack for readability, since some
86   # terminals treat these emoji chars as single-width.
87   local counter=1
88   for i in $names; do
89     if [[ "$group" == "flags" ]]; then 
90       printf '%s  ' "$emoji_flags[$i]"
91     else 
92       printf '%s  ' "$emoji[$i]" 
93     fi
94     # New line every 20 emoji, to avoid weirdnesses
95     if (($counter % 20 == 0)); then
96       printf "\n" 
97     fi
98     let counter=$counter+1
99   done
100   print
101   for i in $names; do
102     if [[ "$group" == "flags" ]]; then 
103       echo "${emoji_flags[$i]}  = $i"
104     else 
105       echo "${emoji[$i]}  = $i"
106     fi
107   done
108 }
109
110