Colour on the command line

From CLUG Wiki

Jump to: navigation, search

newpage icon WARNING: This is a new page.

This is a new page, and might contain technically incorrect information. Please use at your own risk. If you are able to correct any errors or expand this document, please do so.


Contents

Colourful prompt

The Bash Prompt HOWTO is a good start with this.

Debian ships with this coloured prompt:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Jonathan Hitchcock recommends (well, Stefano added the chroot bit, but otherwise, Jonathan recommends):

# Vhata colour prompt
if [ `/usr/bin/whoami` = 'root' ]; then
  PS1='${debian_chroot:+($debian_chroot)}\A/$? \[\033[01;31m\]\h \[\033[01;34m\]\w \$ \[\033[00m\]'
else
  PS1='${debian_chroot:+($debian_chroot)}\A/$? \[\033[01;32m\][\u@\h] \[\033[01;34m\]\w \$ \[\033[00m\]'
fi

Colour-coded ls

In your .bashrc (which on a good Debian system is included from .bash_profile), add

# Nice colourful ls (CLUG-Wiki style)
if [ "$TERM" != "dumb" ]; then
  eval "`dircolors -b`"
  alias ls='ls --color=auto'
fi

Colourful manpages (RedHat style)

In your .bashrc (which on a good Debian system is included from .bash_profile), add

# For colourful man pages (CLUG-Wiki style)
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

Coloured logging

$ apt-cache search log | egrep 'colou?r'
grc - generic colouriser for everything
lwatch - A simple log colorizer
ccze - A robust, modular log coloriser
loco - Perl script to add nice colors to your /var/log/messages file

Less with files containing ESC codes

less -R
eg grc cat /var/log/syslog | less -SR

Highlighting grep output

grep --color blah *

Of course, to make this more convenient, put this in your .bashrc

# Colourful grep
alias cgrep='grep --color'

Fill me out with details!

Colourful vim systax highliting

You can make these changes in one of two places:

# vi /etc/vim/vimrc            # Systemwide
or
$ vi ~/.vimrc                  # Personal

Add (or uncomment)

syntax on

If you use a black-background terminal (which you should), also set

set background=dark

Colourful SPAM in mutt

Read Joe's mutt page, for some colourizing.

Colourful diff

Dave Ewart's colordiff, a Perl script wrapper for 'diff' which produces the same output but with pretty 'syntax' highlighting.

MORE!

I want this page to be 2000 screenfulls long, add more, please!

Table

Work in progress...

Multiplication table
× 1 2 3
1 1 2 3
2 2 4 6
3 3 6 9
4 4 8 12
5 5 10 15