I have 2 Macs, an old iMac in my study and a MacMini in my workshop. I have iTerm2 on both of them. The MacMini is new and I'm still fine tuning the setup. I use zsh for my shell on both and the same .zshenv on both. I have done all I can to make sure I'm using the same iTerm2 settings on both. The problem is that I can set the prompt in .zshenv on my iMac, but the same .zshenv script does not do a thing to the prompt on my new MacMini. (And I have changed the shell to zsh and have checked to be sure I have.) I am NOT using Oh-my-zsh. I just found out about that and may add it later, but this issue is really irritating me and I want to get it fixed.
Here's the relevant code:
PROMPT='%F{magenta}%B[%b%D %* %n@%m %1~%B]%b $ %f'
uname=`whoami`
if [[ "$uname" == "root" ]]; then
PROMPT='%F{red}%B[%b%D %* %n@%m %1~%B]%b $ %f'
fi
echo "Prompt = $PROMPT"
export LS_COLORS
echo "About to export prompt"
echo "Prompt = $PROMPT"
export PROMPT
I'm getting the following behaviors:
- When I open a new window or tab, it reports the proper value for $PROMPT from the script. It does not change my prompt from
%n@%m %1~ %#
. - When I check the value (after .zshenv as run), it comes out to
%n@%m %1~ %#
. - If I copy and paste the line from the script that sets the prompt, it changes the prompt to what I want.
- If I type
./.zshenv
it runs and I get DOUBLE output from the echo commands, as if it's run the script twice and it does not change the prompt. - If I type
source .zshenv
it runs, I don't get repeated output, and the prompt changes. - If I copy the line that defines the prompt from the file and paste it into the terminal, it changes the prompt.
- When I check other variable values and aliases from .zshenv, they have been imported into the shell from the script.
I also just checked on the normal terminal program. I had not thought to check this before. I get the same behaviors on the normal Mac terminal program, too.
This is the same script from my older Mac (which as been kept up to date with regular Apple upgrades), but it behaves differently on this Mac.
./.zshenv
, I would conclude thatPROMPT
(or the equivalentPS1
) gets overwritten after you set it. Of course ~/.zshenv is an unusual location for setting the prompt (we ususally would do it in ~/.zshrc), but you can easily check where the prompt gets overwritten by starting a new shell withzsh -lx
.