annotate bin/termcolors.sh @ 144:1783152a1fe6

Color template for bash.
author Edho Arief <edho@myconan.net>
date Sun, 02 Oct 2011 04:17:53 +0700
parents
children c3ca45204c4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
144
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
1 #!/bin/sh
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
2
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
3 _c() {
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
4 color_name="${1}"
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
5 shift
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
6 text="${*}"
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
7 esq="\033["
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
8 r="${esq}0m" # r for reset
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
9 case "${color_name}" in
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
10 bold_*) color="1;";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
11 *) color="0;";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
12 esac
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
13 case "${color_name}" in
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
14 *black) color="${color}30";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
15 *blue) color="${color}34";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
16 *green) color="${color}32";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
17 *cyan) color="${color}36";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
18 *red) color="${color}31";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
19 *purple) color="${color}35";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
20 *brown) color="${color}33";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
21 *gray) color="${color}37";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
22 esac
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
23 color="${esq}${color}m"
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
24 printf "${color}%s${r}" "${text}"
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
25 }
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
26