emotty.plugin.zsh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # Handle $0 according to the standard:
  13. # # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
  14. 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
  15. 0="${${(M)0:#/*}:-$PWD/$0}"
  16. typeset -gAH _emotty_sets
  17. local _emotty_plugin_dir="${0:h}"
  18. source "$_emotty_plugin_dir/emotty_stellar_set.zsh"
  19. source "$_emotty_plugin_dir/emotty_floral_set.zsh"
  20. source "$_emotty_plugin_dir/emotty_zodiac_set.zsh"
  21. source "$_emotty_plugin_dir/emotty_nature_set.zsh"
  22. source "$_emotty_plugin_dir/emotty_emoji_set.zsh"
  23. source "$_emotty_plugin_dir/emotty_love_set.zsh"
  24. unset _emotty_plugin_dir
  25. emotty_default_set=emoji
  26. function emotty() {
  27. # Use emotty set defined by user, fallback to default
  28. local emotty=${_emotty_sets[${emotty_set:-$emotty_default_set}]}
  29. # Parse tty number via prompt expansion. %l equals:
  30. # - N if tty = /dev/ttyN
  31. # - pts/N if tty = /dev/pts/N
  32. local tty=${${(%):-%l}##pts/}
  33. # Normalize it to an emotty set index
  34. (( tty = (tty % ${#${=emotty}}) + 1 ))
  35. local character_name=${${=emotty}[tty]}
  36. echo "${emoji[${character_name}]}${emoji2[emoji_style]}"
  37. }
  38. function display_emotty() {
  39. local name=${1:-$emotty_set}
  40. echo $name
  41. for i in ${=_emotty_sets[$name]}; do
  42. printf "${emoji[$i]}${emoji2[emoji_style]} "
  43. done
  44. print
  45. for i in ${=_emotty_sets[$name]}; do
  46. print "${emoji[$i]}${emoji2[emoji_style]} = $i"
  47. done
  48. }