1

I am using Catalina(the default shell is zsh) and I want to figure out what happen after executing zsh. I thought it would tell you that "You are using zsh" or something like this. Instead, it showed me this

I tried to figure out current prompt definition in .zshrc or .zprofile, but the only thing I found is a bash_profile, which completely confused me.

I mean this isn't the prompt format when I changed into Bash in 1st picture either. What does this definition serve for? It actually drives me crazy.

I want to know what happen after I execute zsh and why it leads to prompt changed. I know that to further customize prompt I probably could create a .zshrc or .zprofile file. But I am really curious about where is default prompt format defined. How can I simply revert it without adding new file (override the default one)?

2
  • Have you checked the system-wide config files, /etc/zshrc or maybe /etc/zsh/...?
    – mpy
    Commented Jul 27, 2019 at 8:59
  • @mpy yeah, I think u r right. It seems those file contains necessary defination.
    – ychz
    Commented Jul 29, 2019 at 5:23

2 Answers 2

1

The default prompt for zsh on macOS is in /etc/zshrc. It looks like this, at lines 69-70:

# Default prompt
PS1="%n@%m %1~ %# "

If you want to change this prompt, or even add a message like "You are now using zsh", you should override it in your user settings, by creating .zshrc in your home directory (or ~/.zshrc for short).

Don't worry about creating extra files - you should go ahead and do just that, because if Apple decides to change the default settings in a future version of macOS, your changes in /etc/zshrc will be overwritten by the OS upgrade.

Now, to answer the question in the title, I'm not sure exactly why the machine name changes when you restart the shell, but it has something to do with how macOS looks up the name of your computer on the network.

This answer and this answer on the Apple StackExchange go into all the various ways macOS uses DHCP and reverse DNS lookups to try to determine your computer's name, even if you have already set it in the Sharing preferences.

There must be two different places, like in your Sharing settings and in your wifi router config, that have slightly different names configured for your computer. When you start a new copy of zsh, one or the other takes precedence, and the name flips.

To fix this, I'd first make sure you have set the name of your computer in the Sharing settings. If that still doesn't work, you can override the HostName setting on your computer which should always take precedence:

% sudo scutil --set HostName "Yichis-MacBook-Pro"
1

Not fully understand how things work. But here is my understanding:

After enter zsh, terminal creates a new process triggered by zsh. Same thing happens when executing bash. If now you tried to close current terminal window after executing zsh and bash, it will alert that "you are trying to terminate running processes zsh(2) and bash". That's exact amount of each type of process.

Simply enter exit to exit current process. And keep exit until all extra processes are gone, then the familiar prompt should be there.

You must log in to answer this question.

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