Sample Header Ad - 728x90

Cross-platform method of checking if using terminal emulator or tty

0 votes
0 answers
56 views
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)
Asked by Sarp User (21 rep)
Oct 17, 2024, 01:10 AM