shell颜色脚本

shell颜色脚本

#!/bin/bash
desc(){
echo "# Author: royoy
# Ver   : v0.0.3
# Date  : 2014/11
# Mail  : royoy@royoy.com
# Desc  : font [-f|-d|-b|-t|-n|-v|-black|-red|-green|-yellow|-blue|-purple|-cyan|-gray|-reset]
# Usage : font -color1 message1 -reset -color2 message2 -reset ...
#  eg   :    font -red  message1 -reset -n -green message2 -reset -n
#  eg   :    font -f 3 \= -n"
}

format(){
for i in $(seq $1)
do
        echo -n "$2"
        sleep 0.001
done
}

function font {
while [ $# -ne 0 ]
do
   case $1 in
        -f )   format "$2" "$3";shift 2;;
        -d )   echo -ne "`date`  ";;
        -b )   echo -ne " ";;
        -t )   echo -ne "\t";;
        -n )   echo -ne "\n";;
	-v|-V|-h|-help|--help|-version|--version )   desc;;
        -black )   echo -ne "\033[30m";;
        -red )   echo -ne "\033[31m";;
        -green )   echo -ne "\033[32m";;
        -yellow )   echo -ne "\033[33m";;
        -blue )   echo -ne "\033[34m";;
        -purple )   echo -ne "\033[35m";;
        -cyan )   echo -ne "\033[36m";;
        -gray )   echo -ne "\033[37m";;
        -reset )   echo -ne "\033[0m";;
        * )
                echo -ne "$1";;
    esac
    shift
done
}

font "$@"