6

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?

1
3

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 the PS1 line to root's .bashrc should do the trick.

0
6

I was going to add PS1, following the answer by Alaa Ali, and I've found the following lines:

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=no

I've changed it to force_color_prompt=yes, then exit, login back, and voilà! Colors!

I'm on Ubuntu (disco), hope that this help. I think that it's better than PS1 because there's a lot of code that depends on this variable, I don't know exactly what's doing, but somebody has written it, I don't want to waste his/her time :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.