2015-07-15 08:56:48 +02:00
|
|
|
# emoji plugin
|
|
|
|
#
|
|
|
|
# Makes emoji support available within ZSH
|
|
|
|
#
|
2015-07-15 23:16:59 +02:00
|
|
|
# See the README for documentation.
|
2015-07-15 08:56:48 +02:00
|
|
|
|
2021-12-18 21:53:49 +01:00
|
|
|
# Handle $0 according to the standard:
|
2021-12-28 14:16:54 +01:00
|
|
|
# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
|
2021-12-18 21:53:49 +01:00
|
|
|
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
|
|
|
0="${${(M)0:#/*}:-$PWD/$0}"
|
|
|
|
|
2015-07-15 08:56:48 +02:00
|
|
|
_omz_emoji_plugin_dir="${0:h}"
|
|
|
|
|
|
|
|
() {
|
|
|
|
|
|
|
|
local LC_ALL=en_US.UTF-8
|
2014-01-19 05:26:21 +01:00
|
|
|
|
2015-07-15 08:56:48 +02:00
|
|
|
typeset -gAH emoji_skintone
|
|
|
|
|
|
|
|
source "$_omz_emoji_plugin_dir/emoji-char-definitions.zsh"
|
|
|
|
unset _omz_emoji_plugin_dir
|
|
|
|
|
|
|
|
# These additional emoji are not in the definition file, but are useful in conjunction with it
|
|
|
|
|
2021-12-01 12:20:31 +01:00
|
|
|
# This is a combining character that can be placed after any other character to surround
|
2015-07-15 08:56:48 +02:00
|
|
|
# it in a "keycap" symbol.
|
2024-03-26 09:55:16 +01:00
|
|
|
# The digits 0-9 are already in the emoji table as keycap_digit_<N>, keycap_ten, etc.
|
2015-07-15 08:56:48 +02:00
|
|
|
# It's unclear whether this should be in the $emoji array, because those characters are all ones
|
|
|
|
# which can be displayed on their own.
|
|
|
|
|
|
|
|
emoji[regional_indicator_symbol_letter_d_regional_indicator_symbol_letter_e]=$'\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA'
|
|
|
|
emoji[regional_indicator_symbol_letter_g_regional_indicator_symbol_letter_b]=$'\xF0\x9F\x87\xAC\xF0\x9F\x87\xA7'
|
|
|
|
emoji[regional_indicator_symbol_letter_c_regional_indicator_symbol_letter_n]=$'\xF0\x9F\x87\xA8\xF0\x9F\x87\xB3'
|
|
|
|
emoji[regional_indicator_symbol_letter_j_regional_indicator_symbol_letter_p]=$'\xF0\x9F\x87\xAF\xF0\x9F\x87\xB5'
|
|
|
|
emoji[regional_indicator_symbol_letter_k_regional_indicator_symbol_letter_r]=$'\xF0\x9F\x87\xB0\xF0\x9F\x87\xB7'
|
|
|
|
emoji[regional_indicator_symbol_letter_f_regional_indicator_symbol_letter_r]=$'\xF0\x9F\x87\xAB\xF0\x9F\x87\xB7'
|
|
|
|
emoji[regional_indicator_symbol_letter_e_regional_indicator_symbol_letter_s]=$'\xF0\x9F\x87\xAA\xF0\x9F\x87\xB8'
|
|
|
|
emoji[regional_indicator_symbol_letter_i_regional_indicator_symbol_letter_t]=$'\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9'
|
|
|
|
emoji[regional_indicator_symbol_letter_u_regional_indicator_symbol_letter_s]=$'\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8'
|
|
|
|
emoji[regional_indicator_symbol_letter_r_regional_indicator_symbol_letter_u]=$'\xF0\x9F\x87\xB7\xF0\x9F\x87\xBA'
|
|
|
|
|
|
|
|
# Easier access to skin tone modifiers
|
|
|
|
emoji_skintone[1_2]=$'\U1F3FB'
|
|
|
|
emoji_skintone[3]=$'\U1F3FC'
|
|
|
|
emoji_skintone[4]=$'\U1F3FD'
|
|
|
|
emoji_skintone[5]=$'\U1F3FE'
|
|
|
|
emoji_skintone[6]=$'\U1F3FF'
|
2014-01-19 05:26:21 +01:00
|
|
|
}
|
|
|
|
|
2015-07-15 08:56:48 +02:00
|
|
|
# Prints a random emoji character
|
|
|
|
#
|
|
|
|
# random_emoji [group]
|
|
|
|
#
|
|
|
|
function random_emoji() {
|
|
|
|
local group=$1
|
|
|
|
local names
|
|
|
|
if [[ -z "$group" || "$group" == "all" ]]; then
|
|
|
|
names=(${(k)emoji})
|
|
|
|
else
|
2015-08-16 22:26:33 +02:00
|
|
|
names=(${=emoji_groups[$group]})
|
2015-07-15 08:56:48 +02:00
|
|
|
fi
|
2015-08-16 22:30:56 +02:00
|
|
|
local list_size=${#names}
|
|
|
|
[[ $list_size -eq 0 ]] && return 1
|
2014-01-19 05:26:21 +01:00
|
|
|
local random_index=$(( ( RANDOM % $list_size ) + 1 ))
|
2015-07-15 08:56:48 +02:00
|
|
|
local name=${names[$random_index]}
|
2024-03-26 09:55:16 +01:00
|
|
|
if [[ "$group" == "flags" ]]; then
|
2019-08-10 03:56:57 +02:00
|
|
|
echo ${emoji_flags[$name]}
|
2024-03-26 09:55:16 +01:00
|
|
|
else
|
2019-08-10 03:56:57 +02:00
|
|
|
echo ${emoji[$name]}
|
|
|
|
fi
|
2014-01-19 05:26:21 +01:00
|
|
|
}
|
|
|
|
|
2015-07-15 08:56:48 +02:00
|
|
|
# Displays a listing of emoji with their names
|
|
|
|
#
|
|
|
|
# display_emoji [group]
|
|
|
|
#
|
|
|
|
function display_emoji() {
|
|
|
|
local group=$1
|
|
|
|
local names
|
|
|
|
if [[ -z "$group" || "$group" == "all" ]]; then
|
|
|
|
names=(${(k)emoji})
|
|
|
|
else
|
|
|
|
names=(${=emoji_groups[$group]})
|
|
|
|
fi
|
|
|
|
# The extra spaces in output here are a hack for readability, since some
|
|
|
|
# terminals treat these emoji chars as single-width.
|
2019-08-10 03:56:57 +02:00
|
|
|
local counter=1
|
2015-07-15 08:56:48 +02:00
|
|
|
for i in $names; do
|
2024-03-26 09:55:16 +01:00
|
|
|
if [[ "$group" == "flags" ]]; then
|
2019-08-10 03:56:57 +02:00
|
|
|
printf '%s ' "$emoji_flags[$i]"
|
2024-03-26 09:55:16 +01:00
|
|
|
else
|
|
|
|
printf '%s ' "$emoji[$i]"
|
2019-08-10 03:56:57 +02:00
|
|
|
fi
|
|
|
|
# New line every 20 emoji, to avoid weirdnesses
|
|
|
|
if (($counter % 20 == 0)); then
|
2024-03-26 09:55:16 +01:00
|
|
|
printf "\n"
|
2019-08-10 03:56:57 +02:00
|
|
|
fi
|
|
|
|
let counter=$counter+1
|
2015-07-15 08:56:48 +02:00
|
|
|
done
|
|
|
|
print
|
|
|
|
for i in $names; do
|
2024-03-26 09:55:16 +01:00
|
|
|
if [[ "$group" == "flags" ]]; then
|
2019-08-10 03:56:57 +02:00
|
|
|
echo "${emoji_flags[$i]} = $i"
|
2024-03-26 09:55:16 +01:00
|
|
|
else
|
2019-08-10 03:56:57 +02:00
|
|
|
echo "${emoji[$i]} = $i"
|
|
|
|
fi
|
2014-01-19 05:26:21 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|