annotate bin/termcolors.sh @ 316:4f6a3bcbdec0

Gattai!
author Edho Arief <edho@myconan.net>
date Sun, 18 Mar 2012 11:34:47 +0700
parents 73e90355bbd7
children
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
145
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
3 # Usage:
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
4 # _c [bold_|]<color> <text>
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
5 #
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
6 # <color> can be one of:
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
7 # black, blue, green, cyan, red, purple, brown, gray
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
8 # Prefix the color with bold_ to use bold style/light color.
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
9 #
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
10 # Example:
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
11 # To print word "Hello" in bold blue:
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
12 # _c bold_blue "Hello"
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
13 #
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
14 # To print text with only one word colored:
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
15 # echo "Hello, $(c green world)."
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
16 #
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
17 # To do:
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
18 # Support for background color, underline, etc.
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
19 #
239
73e90355bbd7 Link to reference.
Edho Arief <edho@myconan.net>
parents: 145
diff changeset
20 # Reference:
73e90355bbd7 Link to reference.
Edho Arief <edho@myconan.net>
parents: 145
diff changeset
21 # Colours, http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
73e90355bbd7 Link to reference.
Edho Arief <edho@myconan.net>
parents: 145
diff changeset
22 #
145
c3ca45204c4e Documentation.
Edho Arief <edho@myconan.net>
parents: 144
diff changeset
23
144
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
24 _c() {
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
25 color_name="${1}"
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
26 shift
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
27 text="${*}"
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
28 esq="\033["
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
29 r="${esq}0m" # r for reset
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
30 case "${color_name}" in
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
31 bold_*) color="1;";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
32 *) color="0;";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
33 esac
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
34 case "${color_name}" in
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
35 *black) color="${color}30";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
36 *blue) color="${color}34";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
37 *green) color="${color}32";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
38 *cyan) color="${color}36";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
39 *red) color="${color}31";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
40 *purple) color="${color}35";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
41 *brown) color="${color}33";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
42 *gray) color="${color}37";;
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
43 esac
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
44 color="${esq}${color}m"
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
45 printf "${color}%s${r}" "${text}"
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
46 }
1783152a1fe6 Color template for bash.
Edho Arief <edho@myconan.net>
parents:
diff changeset
47