How to keep the coloring in bash when using `sudo -i`?
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 :-)
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.