1f078898887bf96e793772a80e0dae1e96eeadc8

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

emotty: fix for undefined $TTY (FreeBSD) (#7844)

See https://github.com/robbyrussell/oh-my-zsh/pull/6731#issuecomment-449653115

Diff

 1diff --git a/plugins/emotty/emotty.plugin.zsh b/plugins/emotty/emotty.plugin.zsh
 2index b0d24c3227f496b156f909addf3f8a886a3c7613..e288b5cfb02bd02fcddd384b96bb3e1f4bb64f75 100644
 3--- a/plugins/emotty/emotty.plugin.zsh
 4+++ b/plugins/emotty/emotty.plugin.zsh
 5@@ -25,8 +25,14 @@ emotty_default_set=emoji
 6 function emotty() {
 7   # Use emotty set defined by user, fallback to default
 8   local emotty=${_emotty_sets[${emotty_set:-$emotty_default_set}]}
 9-  # Parse $TTY number, normalizing it to an emotty set index
10-  (( tty = (${TTY##/dev/tty} % ${#${=emotty}}) + 1 ))
11+
12+  # Parse tty number via prompt expansion. %l equals:
13+  # - N      if tty = /dev/ttyN
14+  # - pts/N  if tty = /dev/pts/N
15+  local tty = ${${(%):-%l}##pts/}
16+  # Normalize it to an emotty set index
17+  (( tty = (tty % ${#${=emotty}}) + 1 ))
18+
19   local character_name=${${=emotty}[tty]}
20   echo "${emoji[${character_name}]}${emoji2[emoji_style]}"
21 }