I run two different terminal emulators with different zsh prompts depending on whether I am in one or the other (with the second being the "default"):
TERM_EMU=$(ps --pid $(ps --pid $$ -o ppid=) -o comm=)
if [ $TERM_EMU = 'term1' ]; then
PS1='term1> '
else
PS1='term2> '
fi
(Where I have taken the terminal emulator name finding command from this question)
However, I also use nnn for file navigation and frequently spawn its subshells. Whenever I enter an nnn subshell, the process id of the terminal emulator found with the ps command becomes nnn, and the shell switches to the "default" prompt. I want to sync the subshell prompts with my main prompt setting.
My first idea was to check if I'm at zero subshell depth first; this would presumably set my shell prompt to a variable that would later be referenced by the subshells:
if [ -z $NNNLVL ]; then
TERM_EMU=$(ps --pid $(ps --pid $$ -o ppid=) -o comm=)
if [ $TERM_EMU = 'term1' ]; then
PS1='term1> '
else
PS1='term2> '
fi
else
PS1="($NNNLVL) $PS1"
fi
This doesn't work; instead, the subshell prompt becomes
(<level>) <hostname>%
which is not at all what I want; apparently the PS1 variable is not carried over to the subshells. How do I force nnn shells to "remember" their parent terminal emulator?