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 + [.
Colors in terminals are determined in two steps:
- the program running in the terminal tells the terminal to use a certain color number;
- the terminal translates each color number into a color value.
Xterm has an escape sequence to change the color value associated with a color number. I don't remember whether PuTTY supports this sequence; I know Mintty does.
set_color_value () {
printf "\\e]4;$1;$2\\a"
}
set_color_value 4 '#6495ed' # set color 4 (blue) to CornflowerBlue
These settings won't survive a terminal reset. You can overcome this difficulty by appending the cursor configuration changing sequence to your terminal's reset string.
- On a terminfo-based system using ncurses, save your terminal's terminfo settings to a file with
infocmp >>~/etc/terminfo.txt
. Edit the description to change the rs1
(basic reset) sequence, e.g. replace rs1=\Ec
by rs1=\Ec\E]4;4;#6495ed\E\\
. With some programs and settings, you may need to change the rs2
(full reset) as well. Then compile the terminfo description with tic ~/etc/terminfo.txt
(this writes under the directory $TERMINFO
, or ~/.terminfo
if unset).
- On a termcap-based system, grab the termcap settings from your termcap database (typically
/etc/termcap
). Change the is
(basic reset) and rs
(full reset) sequences to append your settings, e.g. :is=\Ec\Ec\E]4;4;#6495ed\E\\:
. Set the TERMCAP
environment variable to the edited value (beginning and ending with :
).
Now you can put something like this in your ~/.profile
:
if [ "$(ps -p $PPID -o comm=)" = sshd ] &&
[ "$TERM" = "xterm" ]; then
set_color_value … # set color scheme
TERMCAP=… # if necessary
fi
Best Answer
Running a ruby script on every login doesn't sound like my idea of a good time.
But if it's colours you want you won't be disappointed by
lolcat
https://github.com/busyloop/lolcatDISCLAIMER: I have since set this up on my SSH banners throughout my home cluster :)
Looks great with some text piped in from
figlet