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.
The PATH could be set in any of the various files bash reads when it starts. To find them all, run this:
grep --color -H 'PATH=' ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login \
~/.bash_aliases /etc/bash.bashrc /etc/profile \
/etc/profile.d/* /etc/environment 2> /dev/null
Those are the standard ones. If you are also sourcing other files from one of those, things can get more complex.
Anyway, to fix it—assuming you haven't done anything to the global files in /etc/
—you can run this:
sed -i '/PATH=/d' ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login ~/.bash_aliases
That will delete any lines setting PATH
from those files. Now, add the right one in the right place:
pp='PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jgrande/android-sdk-linux/platform-tools:/usr/lib/jvm/java-7-openjdk-amd64/bin/:/usr/lib/jvm/java-7-openjdk-amd64/jre/bin'
[[ -e '~/.bash_profile' ]] && echo "$pp" >> ~/bash_profile ||
echo "$pp" >> ~/.profile
When invoked as a login shell, bash reads .bash_profile
if present and, if not, it reads ~/.profile
(it will ignore .profile
if .bash_login
is present but I assume it isn't). So, the commands above will first save your desired path as $pp
and then check whether a ~/.bash_profile
exists, add the path definition to it if it does and, if it doesn't, it will add it to ~/.profile
.
In the future, to avoid this kind of issue, use a function to add directories to your $PATH
. Add these lines to your ~/.profile
:
pathmunge ()
{
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)"; then
if [ "$2" = "after" ]; then
PATH=$PATH:$1;
else
PATH=$1:$PATH;
fi;
fi
}
Then, to add something to the beginning of your $PATH
, add this line to ~/.profile
:
pathmunge "/path/to/foo"
And to add it to the end:
pathmunge "/path/to/foo" after
The function will only add a new directory to the $PATH
if it isn't already there.
Best Answer
References
So far, there hasn't been a single reference for everything that can go in a Bash prompt - but as it's a feature that has evolved over decades and probably varies from distro to distro, maybe that's too much to ask. I've tried to summarise what I found most useful here.
This how-to is the most complete, but is very long and rambling. Some of the more useful sections:
\[
and\]
are necessary.This guide explains how
${}
works in Bash in general, and this Ask Ubuntu question explains a bit more about how that works withdebian_chroot
.Between those, I think every character in the default Ubuntu PS1 variable is explained.
Explanation of the Ubuntu prompt
There are three parts to the prompt:
\[\e]0;\u@\h: \w\a\]
sets the title bar of an xterm window:\[
starts a section of non-printable characters\e]0;
is the escape sequence for 'set xterm title' (I believe numbers other than 0 will set other xterm properties, though I haven't tested this)\u@\h: \w
the title to use (see below for\u
,\h
and\w
)\a
marks the end of the title\]
marks the end of non-printable characters${debian_chroot:+($debian_chroot)}
expands to the value of $debian_chroot in parentheses if $debian_chroot is set. See this question for more information about $debian_chroot.\u@\h:\w\$
is the prompt itself:\u
expands to the current username\h
expands to the current hostname\w
expands to the current working directory\$
expands to#
for root and$
for all other users