#!/bin/bash # color-inc # Library to colorize prompt text especially in shell prompt # # Muhammad Ichsan http://michsan.web.id # Oct 2009 # black=0 red=1 green=2 yellow=3 blue=4 magenta=5 cyan=6 white=7 # Borders to prevent messy prompt bfr='\[' afr='\]' # color: The color of the text (0-7) # bgcolor: The background color. Give -1 to give no background color function colorize { text=$1 color=$2 bgcolor=$3 bold=$4 # Specify color color_plate='3'$color # Specify background color [ $bgcolor -lt 0 ] || color_plate=$color_plate';4'$bgcolor # Make text bold or not [ $bold -eq 0 ] || color_plate=$color_plate';'1 begin=$bfr"\e["$color_plate'm'$afr end=$bfr"\e[0m"$afr echo $begin''$text''$end return 0 }