emotty.plugin.zsh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # ------------------------------------------------------------------------------
  2. # FILE: emotty.plugin.zsh
  3. # DESCRIPTION: Return an emoji for the current $TTY number.
  4. # AUTHOR: Alexis Hildebrandt (afh[at]surryhill.net)
  5. # VERSION: 1.0.0
  6. # DEPENDS: emoji plugin
  7. #
  8. # There are different sets of emoji characters available, to choose a different
  9. # set export emotty_set to the name of the set you would like to use, e.g.:
  10. # % export emotty_set=nature
  11. # ------------------------------------------------------------------------------
  12. typeset -gAH _emotty_sets
  13. local _emotty_plugin_dir="${0:h}"
  14. source "$_emotty_plugin_dir/emotty_stellar_set.zsh"
  15. source "$_emotty_plugin_dir/emotty_floral_set.zsh"
  16. source "$_emotty_plugin_dir/emotty_zodiac_set.zsh"
  17. source "$_emotty_plugin_dir/emotty_nature_set.zsh"
  18. source "$_emotty_plugin_dir/emotty_emoji_set.zsh"
  19. source "$_emotty_plugin_dir/emotty_love_set.zsh"
  20. unset _emotty_plugin_dir
  21. emotty_default_set=emoji
  22. function emotty() {
  23. # Use emotty set defined by user, fallback to default
  24. local emotty=${_emotty_sets[${emotty_set:-$emotty_default_set}]}
  25. # Parse $TTY number, normalizing it to an emotty set index
  26. (( tty = (${TTY##/dev/ttys} % ${#${=emotty}}) + 1 ))
  27. local character_name=${${=emotty}[tty]}
  28. echo "${emoji[${character_name}]}${emoji2[emoji_style]}"
  29. }
  30. function display_emotty() {
  31. local name=$1
  32. for i in ${=_emotty_sets[$name]}; do
  33. printf "${emoji[$i]}${emoji2[emoji_style]} "
  34. done
  35. print
  36. for i in ${=_emotty_sets[$name]}; do
  37. print "${emoji[$i]}${emoji2[emoji_style]} = $i"
  38. done
  39. }