I have changed PS1 variable in /etc/bash.bashrc
to
PS1="\n\[\033[0;37m\]\342\224\214\342\224\200\$(if [[ \$? == 0 ]]; then echo \"[\[\033[0;32m\]\[\033[01;32m\]\342\234\223\[\033[0;37m\]]\342\224\200\"; else echo \"[\[\033[0;32m\]\[\033[01;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\"; fi)[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[0;31m\]\h'; else echo '\[\033[0;33m\]\u\[\033[0;37m\]@\[\033[0;96m\]\h'; fi)\[\033[0;37m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;37m\]]\n\[\033[0;37m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]"
Which works fine with all the commands. But when I run sudo -i
command, PS1 value goes to the default. To get back the color scheme, I have to run PS1=<same value>
manually. Any idea what might be causing this behaviour?
Best Answer
Add the
PS1
line to/root/.bashrc
.The reason why the color goes back to default is because when you do
sudo -i
, it "simulates" a root login, and in turn sources (applies) root's.bashrc
, which brings the color back to the default. So adding thePS1
line to root's.bashrc
should do the trick.