emotty.plugin.zsh 1.7 KB
Newer Older
Alexis Hildebrandt's avatar
Alexis Hildebrandt committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ------------------------------------------------------------------------------
#          FILE: emotty.plugin.zsh
#   DESCRIPTION: Return an emoji for the current $TTY number.
#        AUTHOR: Alexis Hildebrandt (afh[at]surryhill.net)
#       VERSION: 1.0.0
#       DEPENDS: emoji plugin
#       
# There are different sets of emoji characters available, to choose a different
# set export emotty_set to the name of the set you would like to use, e.g.:
# % export emotty_set=nature
# ------------------------------------------------------------------------------

typeset -gAH _emotty_sets
local _emotty_plugin_dir="${0:h}"
source "$_emotty_plugin_dir/emotty_stellar_set.zsh"
source "$_emotty_plugin_dir/emotty_floral_set.zsh"
source "$_emotty_plugin_dir/emotty_zodiac_set.zsh"
source "$_emotty_plugin_dir/emotty_nature_set.zsh"
source "$_emotty_plugin_dir/emotty_emoji_set.zsh"
source "$_emotty_plugin_dir/emotty_love_set.zsh"
unset _emotty_plugin_dir

emotty_default_set=emoji

function emotty() {
  # Use emotty set defined by user, fallback to default
  local emotty=${_emotty_sets[${emotty_set:-$emotty_default_set}]}
28
29
30
31
32
33
34
35

  # Parse tty number via prompt expansion. %l equals:
  # - N      if tty = /dev/ttyN
  # - pts/N  if tty = /dev/pts/N
  local tty = ${${(%):-%l}##pts/}
  # Normalize it to an emotty set index
  (( tty = (tty % ${#${=emotty}}) + 1 ))

Alexis Hildebrandt's avatar
Alexis Hildebrandt committed
36
37
38
39
40
  local character_name=${${=emotty}[tty]}
  echo "${emoji[${character_name}]}${emoji2[emoji_style]}"
}

function display_emotty() {
41
42
  local name=${1:-$emotty_set}
  echo $name
Alexis Hildebrandt's avatar
Alexis Hildebrandt committed
43
44
45
46
47
48
49
50
  for i in ${=_emotty_sets[$name]}; do
    printf "${emoji[$i]}${emoji2[emoji_style]}  "
  done
  print
  for i in ${=_emotty_sets[$name]}; do
    print "${emoji[$i]}${emoji2[emoji_style]}  = $i"
  done
}