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
konsole on my Linux box (note: spacing modified to fit on the page):
XTERM_VERSION=XTerm(327) | KONSOLE_DBUS_WINDOW=/Windows/1
WINDOWID=83886094 | WINDOWID=115343366
XAUTHORITY=/tmp/xauth-1000-_0 | XAUTHORITY=/home/anthony/.Xauthority
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.