colorizing bash | Arch Linux

After installing Arch Liunux, I decided that I needed to spruce up my bash environment.

The Arch Linux wiki page on colorizing bash prompt offers us some basic configuration options for colorizing the prompt itself for individual users. One just needs to edit ~/.bashrc by commenting out the defaults and defining one's desired parameter.

Let's say I want a a green prompt:

vi ~/.bashrc
# PS1='[\u@\h \W]\$ '
PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '

Colored prompts are nice and all, but I'm after a slightly more colorful environment: one that makes my 'ls' outputs pretty and allows me to easily discern a file from a folder. To accomplish this, I needed a few more lines of code:

# ~/.bashrc

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

# ATTEMPT: redefine bash colors
if [ "$TERM" = "linux" ]; then

echo -en "\e]P0000000" #black
echo -en "\e]P8393939" #bright-black
echo -en "\e]P1ff3a3a" #red
echo -en "\e]P9ff6d6d" #bright-red
echo -en "\e]P260b045" #green
echo -en "\e]PAaddaa0" #bright-green
echo -en "\e]P3d9d03f" #yellow
echo -en "\e]PBfff333" #bright-yellow
echo -en "\e]P41895fb" #blue
echo -en "\e]PC06c9fb" #bright-blue
echo -en "\e]P5c46dab" #magenta
echo -en "\e]PDd5b2e1" #bright-magenta
echo -en "\e]P657ddca" #cyan
echo -en "\e]PEaceee5" #bright-cyan
echo -en "\e]P7f8f8f8" #white
echo -en "\e]PFdedede" #white-grey
clear #for background artifacting


Testing color choices for can be facilitated a script a script to print your color pallet. [NOTE: Scripts need +x permission in order to run the . preface.]

For example:

#touch print
#vim print

-then paste in the script-

# tputcolors

echo -e "$(tput bold) reg  bld  und   tput-command-colors$(tput sgr0)"

for i in $(seq 1 7); do
  echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0)  \$(tput setaf $i)"

echo ' Bold            $(tput bold)'
echo ' Underline       $(tput sgr 0 1)'
echo ' Reset           $(tput sgr0)'

-enable execution and run it-

chmod +x print

I'm pretty happy with the results.

... After I eventually settled on xmonad for my window manager (WM), I discovered that xterm draws color settings from ~/.Xresources, and that I would have to tell my xterm programme to merge in my user settings before it would actually load my colors.

Once loaded, I had to stop and start X before setting changes would take effect... resulting in a more time intensive period of fine-tuning and adjusting. I eventually got my xterm looking how I wanted by fooling with ~./Xresources and giving it a similar color scheme. To stop it from showing bolded files, I used these settings:

xterm*font: fixed
xterm*boldFont: fixed

To automate the loading of your color palate, add some additional configuration parameters to ~/.xinrc

Now I just need to figure out how to colorize vim.

View or Post Comments