How do I set the prompt to use two colors?
Solution 1
Run the following command in a terminal:
gedit ~/.bashrc
When .bashrc
opens, locate and uncomment force_color_prompt=yes
(that is, remove the hash, so it no longer looks like: #force_color_prompt=yes
).
Save the file, and open a new terminal window, and you should already see a change (the prompt should be Light Green, which is defined by 1;32). You can then change any colour value you like; eg: 0;35 = Purple.
To edit the colour values, locate the following section, and change the default values with some of the examples listed further down:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
You can check out this Bash colour chart for a full range of colour values, but here are a few basic ones you can play around with (note that “Light” isn’t what you might think – it actually means “bold”): Black 0;30 – Dark Gray 1;30 – Blue 0;34 – Light Blue 1;34 – Green 0;32 – Light Green 1;32 – Cyan 0;36 – Light Cyan 1;36 – Red 0;31 – Light Red 1;31 – Purple 0;35 – Light Purple 1;35 – Brown 0;33 – Yellow 1;33 – Light Gray 0;37 – White 1;37
For example, here is the line that I use it:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;34m\] \w\[\033[01;37m\] > '
or, my girlfriend, use:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;31m\]@\[\033[01;36m\]\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\# '
Feel free experimenting by setting your prompt by changing the value of the PS1 environment variable in Terminal, as follows:
export PS1="...your values..."
or, just
PS1="...your values..."
Here is how my terminal look:
Solution 2
Simply modify $PS1
in the shell startup files with the appropriate calls to tput
in order to set and clear text attributes. See the tput(1)
and terminfo(5)
man pages for details.
export PS1="\[$(tput setaf 2)\][\u@\h \W]\$ \[$(tput sgr0)\]"
Solution 3
You can try this one:
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
(try it in a terminal first). Then, if you like it, you can put it somewhere in your .bashrc
file.
Solution 4
This thing you are talking about is called prompt. There are lots of options and scripts to modify your prompt using different colors and displaying any kind of additional information. A good start with some examples can be found within jamie's collection and IBM has some nice explanations for beginners. If you want to go more into detail have a look at this comprehensive howto
Related videos on Youtube
TSJNachos117
I've been using both Ubuntu and Linux Mint since April 2013. I may not know too much in general about GNU/Linux at the time of writing this, but I learn more everyday. I'm a long-time Windows nerd, growing up with Windows 98, and learning other Windows versions as I go, even if it means doing so through Betas. However, my movement to GNU/Linux has been largely due to Microsoft's bad decision making strategies as of late. Ever since that long gap between the release of XP and Vista, I've found myself wondering "What were they thinking?" Now, I've come to see them as a threat to the computer industry, itself. I've also learned just how restrictive Microsoft's licensing can be, allowing only a handful of PC's to run a certain license/copy of Windows (or many of Microsoft's other products), while using short-sighted "anti-piracy" DRM-oriented tactics to enforce this, often at the frustration and expense of their own paying customers. As we all know Linux distros like Ubuntu are different, in that they are meant to be free, and not just to use... free to distribute, study, and modify, allowing it's users to use the software to its maximum potential. That, I assume, is why the world's 10 fastest super computers run some form of Linux. Thanks, Torvalds, FSF, and Richard Stallman, for granting us the freedoms that Microsoft may never allow us to have....
Updated on September 18, 2022Comments
-
TSJNachos117 over 1 year
One thing I liked about Mint was that the terminal would usually show two colors: everything from the left to the
$
would be one color, and everything past the$
would be another.Is there a way to have this setup with Ubuntu?
-
TSJNachos117 about 9 yearsFYI I found the /etc/bash.bashrc file from Mint 14 on pastebin. The very first and very last lines need to be removed, or you'll get an error. Also, it might be a good idea if the ~/.bash_aliases file is loaded, assuming such a file exsists.
-
-
Ignacio Vazquez-Abrams almost 11 years@RaduRădeanu: "in the shell startup files"
-
Radu Rădeanu almost 11 yearsBetter shell initialization files
-
ARAVIND P over 8 yearswhere does the flower photo come from?
-
wjandrea over 6 yearsInstead of
$(tput setaf 2)
and$(tput sgr0)
, I'd recommend using the ANSI escape sequences directly:\033[32m
and\033[m
. The result is the same, but it doesn't require a call. -
Admin almost 2 yearsLink is broken :(