How to make terminal to follow local hostname from settings?

I do not know what happened, but before I had I kind of sync between macOS settings for local hostname and the host name I see in the terminal app. For instance if I change host name in settings it automatically updates terminal. At some point it stopped to work and I do not know how to bring this feature back.


MacBook Air 15″

Posted on Mar 1, 2024 10:08 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 3, 2024 5:47 AM

One thing I do in my Zsh startup file (~/.zshrc) is ensure that my prompt is always my local hostname, and not a supplanted reverse DNS host name provided by a VPN. My free University VPN service for alumni was recently elimninated as an Alumni service, so I am not now using VPN.


# don't want VPN DNS changing my hostname
MyHost="$(networksetup -getcomputername)"
PS1="${MyHost}: %~ %# "


and my Zsh shell prompt becomes:

odin: ~ %



This would work in the Bash shell's ~/.bash_profile or ~/.bashrc as well with adjustments for Bash PS1 syntax.

MyHost="$(networksetup -getcomputername)"
export PS1="$MyHost: \w $ "



19 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to make terminal to follow local hostname from settings?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.