0

I am looking for a cross platform way to check if I am using a terminal emulator (with support for unicode characters) or a TTY session (with only support for ASCII chars). I initially tried to use if [[ $(tty) =~ /dev/tty ]]. This worked well on Linux; I was able to distinguish between the TTY session and a terminal emulator. The issue arises with Mac. All Mac terminal emulators return /dev/tty... from the tty command. I then saw suggestions to use $WINDOWID, $DISPLAY and $TERM_PROGRAM. The issue then becomes that not all terminal emulators set these variables.

So my question is this: Is there a surefire way to reliably tell if you are using a terminal emulator or a TTY session? I know that i could theoretically create an if statement that checks for all of those but I am not a big fan of doing that. Is there a cleaner way to do this?

(This is for importing my prompt to use Nerd fonts or not)

2
  • Given that the need comes from compatibility with your local Nerd fonts configuration, is a generic check actually necessary? Suppose you use Konsole and iTerm2 and have configured them to use Nerd fonts – find a way to check for Konsole and iTerm2 and only activate the fonts in those?
    – grawity
    Commented Oct 17, 2024 at 8:15
  • The distinction you draw is wrong, I think – there's no guarantee a terminal emulator supports unicode, and there's no guarantee a physical TTY (I'd be interested to see one) would not. I think what you actually want to know is "Does my terminal support UTF?" (and you don't really care about what kind of terminal that is). Am I interpreting you correctly? Commented Oct 17, 2024 at 13:25

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.