I've recently jumped ship to zsh and I'm using the Oh my Zsh! theme blinks. It looks very nice in the OSX Terminal, but it looks very bad in Android Studio's terminal.

So my question is is there a way to check that this session has been opened in Android Studio and not in the OSX Terminal and change the zsh theme according to that?

enter image description here

enter image description here

  • 1
    I don't have an answer, but I think this is just an issue with Intellij in general. I posted this on their forums a while ago. Would love to know the answer myself.
    – jktravis
    Jan 19, 2015 at 14:31
  • I'm not sure I understand the problem, but it's easy enough to just run a little script to change 'PS1' from whatever to whatever. Looks like you want to change the background color mostly. Jan 24, 2015 at 4:29
  • 2
    As a sort of kludge, you may try traversing PID tree starting from your parent process ($PPID) up to the very PID 1. If you see there's java, switch the theme.
    – drdaeman
    Jul 17, 2016 at 13:58

1 Answer 1


Since no one else has given you an answer, I'm trying despite having completely different software. So this is a generic answer on how to do it with any software. There are two approaches that come to mind:

1. Different environments

Open Terminal, and run env > env.terminal. Open Android Studio, and run env > env.studio. Now, in either terminal, you can run diff -dby --suppress-common-lines env.terminal env.studio (if Mac OS X diff has those options; if not -U1 works well enough).

As an example, here is the difference between xterm and konsole on my Linux box (note: spacing modified to fit on the page):

                                   > PROFILEHOME=
                                   > SHELL_SESSION_ID=1e8d5ab2d16641668485f991a1beffe3
                                   > QSG_RENDER_LOOP=
                                   > COLORTERM=truecolor
XTERM_SHELL=/bin/bash              <
                                   > KONSOLE_DBUS_SESSION=/Sessions/1
XTERM_VERSION=XTerm(327)           | KONSOLE_DBUS_WINDOW=/Windows/1
TERM=xterm                         <
                                   > TERM=xterm-256color
                                   > KONSOLE_DBUS_SERVICE=:1.1514
                                   > QMLSCENE_DEVICE=
                                   > KONSOLE_PROFILE_NAME=Default
                                   > COLORFGBG=15;0
WINDOWID=83886094                  | WINDOWID=115343366
XAUTHORITY=/tmp/xauth-1000-_0      | XAUTHORITY=/home/anthony/.Xauthority
XTERM_LOCALE=en_US.UTF-8           <

Some of that stuff is clearly noise from how I launched the two different terminals. But others are not. If I wanted something only in XTerm, then if [ -n "$XTERM_VERSION" ] would seem to be a pretty good way to do that. Similarly, for Konsole, $KONSOLE_PROFILE_NAME would be a good one (and probably a few of the others, too).

2. Different parent processes

A shell knows its own process ID, it can be accessed via $$. POSIX also has $PPID to get the parent PID directly, so I suspect you have that in zsh too. If not, ps can get it for you: ppid=$(ps -o ppid= $$). You can then get the command run, also with ps:

xterm:~$ ps -o args= $PPID

konsole:~$ ps -o args= $PPID

(You can try -o comm= as well).

In a shell script, it'd look something like:

ppid=$(ps -o ppid= $$)   # if you don't have PPID for some reason
if [ "$(ps -o args= $ppid)" = "/usr/bin/xterm" ]; then
  echo "do xterm stuff"

If you need to go further up the process tree, you can use ps to get the parent's parent, etc.

You must log in to answer this question.

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