I have a standard user account (in Mojave using zsh shell) and based on Gentoo Wiki I have added this to my .zshrc to show a prompt like [user@computer] ~ $
if [[ $UID == 0 ]]; then
PS1="[%n@%M] %~ # "
else
PS1="[%n@%M] %~ $ "
fi
I changed root shell to zsh with sudo chsh -s /bin/zsh
but sudo su
gives an incorrect (presumably default) prompt unless I re-source my .zshrc
:
[hali@A1398] ~ $ sudo su
A1398# echo $PS1
%m%#
A1398# source .zshrc
[root@A1398] /Users/hali #
Based on sourcing bash profile for root users and What are the practical differences between Bash and Zsh I copied my .zshrc
for root to use with cp ~/.zshrc /var/root/
Similarly I also have a hidden admin account set up according to this Apple doc and so su admin
also shows its' default prompt unless I also do cp ~/.zshrc /var/admin/
If I copy both it then works as I want - the user(%n
) is shown before the computer name(%M
):
[hali@A1398] ~ $ sudo cp .zshrc /var/root/
[hali@A1398] ~ $ sudo cp .zshrc /var/admin/
[hali@A1398] ~ $ sudo su
[root@A1398] /Users/hali # su admin
[admin@A1398] /Users/hali $ exit
[root@A1398] /Users/hali # exit
[hali@A1398] ~ $
Is there any way to use one copy of .zshrc
for these three accounts to share or somehow automatically keep them in sync as I make further changes to this file?
sudo su -l
fix the issue,in other words, prevent the need to source.zshrc
?sudo su -l
didn't work so I make symlinks for.zshrc
and also rantouch /var/root/.histfile
aszsh-newuser-install
didn't seem to work for root user.