Here are a couple of things you can do:
Editors + Code
A lot of editors have syntax highlighting support. vim
and emacs
have it on by default. You can also enable it under nano
.
You can also syntax highlight code on the terminal by using Pygments as a command-line tool.
grep
grep --color=auto
highlights all matches. You can also use export GREP_OPTIONS='--color=auto'
to make it persistent without an alias. If you use --color=always
, it'll use colour even when piping, which confuses things.
ls
ls --color=always
Colors specified by:
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33'
(hint: dircolors
can be helpful)
PS1
You can set your PS1 (shell prompt) to use colours. For example:
PS1='\e[33;1m\u@\h: \e[31m\W\e[0m\$ '
Will produce a PS1 like:
[yellow]lucas@ubuntu: [red]~[normal]$
You can get really creative with this. As an idea:
PS1='\e[s\e[0;0H\e[1;33m\h \t\n\e[1;32mThis is my computer\e[u[\u@\h: \w]\$ '
Puts a bar at the top of your terminal with some random info. (For best results, also use alias clear="echo -e '\e[2J\n\n'"
.)
Getting Rid of Escape Sequences
If something is stuck outputting colour when you don't want it to, I use this sed
line to strip the escape sequences:
sed "s/\[^[[0-9;]*[a-zA-Z]//gi"
If you want a more authentic experience, you can also get rid of lines starting with \e[8m
, which instructs the terminal to hide the text. (Not widely supported.)
sed "s/^\[^[8m.*$//gi"
Also note that those ^[s should be actual, literal ^[s. You can type them by pressing ^V^[ in bash, that is Ctrl + V, Ctrl + [.
Best Answer
Method #1 - Using dconf
Background
You can use the
dconf
tool to accomplish this, however it's a mult-step process.Usage
General approach
First you'll need to get a list of your
gnome-terminal
profiles.Using this
<profile id>
you can then get a list of configurable settingsYou can then read the current colors of either the foreground or background
foreground
background
You can change the colors as well
foreground
background
Example
Get my profile ID
Use the profile ID to get a list of settings
Change your background blue
A Note on colors
You can use either the notation
rgb(R,G,B)
when specifying your colors or the hash notation#RRGGBB
. In the both notations the arguments are red, green, and blue. The values in the first notation are integers ranging from 0-255 for R, G, or B. In the second notation the values are in hexidecimal ranging from 00 to FF for RR, GG, or BB.When providing either of these to
dconf
you need to wrap it properly in double quotes with single quotes nested inside. Otherwisedconf
will complain."'rgb(0,0,0)'"
"'#FFFFFF'"
Method #2 - Using gconftool-2
On my Ubuntu 12.04 system I was able to change the colors via the command line as follows.
NOTE: The options are ultimately stored in this file,
$HOME/.gconf/apps/gnome-terminal/profiles/Default/%gconf.xml
.General approach
First you'll need to get the tree for
gnome-terminal
's profile.Using the resulting tree we can find out what attributes are configurable.
Get/Set the
background_color
&foreground_color
attributesConfirm
References