Synchronise or share .zshrc between accounts

Solution 1:

Use a symlink. It uses the ln command in the terminal

ln -s ~/.zshrc /var/root/.zshrc

You can replace /var/root with whatever you need to. This will create a file named .zsrhc in /var/root that is linked to the original copy in your home directory. Please note that you may need sudo before this if you do not have file permissions.

Solution 2:

Zsh will read up to 5 "global" rc files on startup depending on its shell classification, ie. login or non-login, interactive or non-interactive and their content is available to all zsh users. These files are /etc/zshenv, /etc/zprofile, /etc/zshrc, /etc/zlogin, and /etc/zlogout. They are read in conjunction with 5 "dot files", usually found in your home directory .zshenv, .zprofile, .zshrc, .zshlogin, and .zshlogout. In your case, /etc/zshrc would be a good candidate.

You can replace-

if [[ $UID == 0 ]]; then
   PS1="[%n@%M] %~ # "
else
   PS1="[%n@%M] %~ $ "
fi

with this one line

PROMPT='[%n@%M] %~ %(!.#.$) '

The %(!.#.$) is a conditional statement which reads:

if the shell is privileged (!) then place the text # at the end of the prompt else place a $ at the end of the prompt. (This syntax seems alot like cshsyntax.)

Enjoy!