I typically use iTERM2 with zsh and Oh My Zsh! themes. My current theme uses color control commands and a Powerline font:

# vim:ft=zsh ts=2 sw=2 sts=2

# Must use Powerline font, for \uE0A0 to render.
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}\uE0A0 "


%{$fg_bold[grey]%}%n@%m%{$fg_bold[white]%}:%{$fg_bold[green]%}$(shrink_path --fish)%{$reset_color%}$(git_prompt_info) ⌚ %{$fg_bold[red]%}%*%{$reset_color%}
$ '


Anyways. On the rare occasion I need to run XQuartz with xterm. Because of the above configuration, xterm cannot deal with the above color codes, and thus emits a bunch of garbage after each prompt:

garbage after prompt in xterm

I've tried testing for xterm using the $TERM variable in my .zshrc and theme files, however it's always xterm.

So my question, what's the best way to detect the terminal environment between XQuartz xterm and iTerm terminal so I can toggle/disable the theme?

  • You don't show the important parts of your script, but there is no reason that xterm would not support escape codes for color. Whatever problem you have, that is not it. Commented Aug 31, 2022 at 19:56
  • What part of the script would you need? This is the part that seemingly sets up the prompt. If I comment out assignment of the PROMPT, everything else just works fine
    – Jim
    Commented Sep 1, 2022 at 20:01
  • @MarcWilson With the assistance of @mmmmmm's answer, I could easily figure out the problem is that the xterm doesn't seem to want to support the watch emoji or SVG powerline fonts that are in use with my prompt.
    – Jim
    Commented Sep 1, 2022 at 20:31
  • Did you install the font in whatever X11 you are running? Commented Sep 1, 2022 at 23:08
  • @MarcWilson I'm using XQuartz. Not sure where it pulls fonts from for it's xfontserver; I would assume since XQuartz is designed for MacOS, it would pull fonts from the user and system fonts directories.
    – Jim
    Commented Sep 2, 2022 at 18:42

1 Answer 1


Try $TERM_PROGRAM this is set by iTerm.app and Terminal.app

I forget if set in xterm - but if it is unset that would be sufficient in this case.

As it is unset the the code to use is put it in this block

if [[ ! -z "$TERM_PROGRAM" ]]; then 
  • This seems to work. Placing the PROMPT assignment in a if [[ ! -z "$TERM_PROGRAM" ]]; then ... block seems to address my immediate need.
    – Jim
    Commented Sep 1, 2022 at 20:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .