emotty.plugin.zsh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 via prompt expansion. %l equals:
  26. # - N if tty = /dev/ttyN
  27. # - pts/N if tty = /dev/pts/N
  28. local tty=${${(%):-%l}##pts/}
  29. # Normalize it to an emotty set index
  30. (( tty = (tty % ${#${=emotty}}) + 1 ))
  31. local character_name=${${=emotty}[tty]}
  32. echo "${emoji[${character_name}]}${emoji2[emoji_style]}"
  33. }
  34. function display_emotty() {
  35. local name=${1:-$emotty_set}
  36. echo $name
  37. for i in ${=_emotty_sets[$name]}; do
  38. printf "${emoji[$i]}${emoji2[emoji_style]} "
  39. done
  40. print
  41. for i in ${=_emotty_sets[$name]}; do
  42. print "${emoji[$i]}${emoji2[emoji_style]} = $i"
  43. done
  44. }