emotty.plugin.zsh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/tty} % ${#${=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:-$emotty_set}
  32. echo $name
  33. for i in ${=_emotty_sets[$name]}; do
  34. printf "${emoji[$i]}${emoji2[emoji_style]} "
  35. done
  36. print
  37. for i in ${=_emotty_sets[$name]}; do
  38. print "${emoji[$i]}${emoji2[emoji_style]} = $i"
  39. done
  40. }