One of the best lessons you can learn from Gentoo is you can export most of its juice to other OSes. I’ve been using Gentoo as main Linux distro since 2001. Currently I have a few setups where drawbacks of migrating to Gentoo would exceed benefits, so I decided to increase affinity by adding some Gentoo look’n'feel. This week I will post some tips to setup Gentoo console colors on other operating systems.
Shell prompt
First of all, you should check you’re using bash shell:
$ env | grep ^SHELL=
SHELL=/bin/bash
If not, you should check if bash package is already installed. If it’s already there, just change your user shell (and possibly root shell) with chsh or consult your OS manual. Be careful: if bash is not listed in /etc/shells, you might lock yourself out.
To set Gentoo-like colors on bash prompt, edit ~/.profile (or /etc/profile for system-wide defaults) and add the following:
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
else
PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
fi
GNU ls
If you use GNU ls (use –version to check) and dircolors utility is available (from GNU coreutils), you can have colorful outputs by adding the following snippet to your bash profile (see above):
if type -P dircolors >/dev/null ; then
if [[ -f ~/.dir_colors ]] ; then
eval $(dircolors -b ~/.dir_colors)
elif [[ -f /etc/DIR_COLORS ]] ; then
eval $(dircolors -b /etc/DIR_COLORS)
fi
fi
alias ls='ls --color=auto'
To enable colors, you need to save Gentoo color defs to ~/.dir_colors (or /etc/DIR_COLORS for system-wide defaults).
Alternatively, if you miss dircolors binary on your system, save output from dircolors on a Gentoo machine and copy’n'paste it into bash profile:
LS_COLORS='...weird colon-separated string...'
export LS_COLORS
alias ls='ls --color=auto'
BSD ls implementation
A special trick is required for FreeBSD and Mac OS X: add the following line to your bash profile:
export CLICOLOR=1 LSCOLORS="ExGxFxDxCxDxDxhbhdacEc"
If you want to further customize colors on your Mac OS X Terminal, you can use SIMBL TerminalColours plugin (Snow Leopard version).
GNU grep
You can enable coloring of the matched part by appending the following alias to your bash profile:
alias grep='grep --colour=auto'
As usual, if you have any coloring tips’n'tricks you want to share, please use the comment box below.