Mercurial > ec-dotfiles
view bin/termcolors.sh @ 584:4130d41c6acb
Support for msys' USERNAME variable
author | nanaya <me@myconan.net> |
---|---|
date | Wed, 09 Mar 2016 15:37:53 +0900 |
parents | 73e90355bbd7 |
children |
line wrap: on
line source
#!/bin/sh # Usage: # _c [bold_|]<color> <text> # # <color> can be one of: # black, blue, green, cyan, red, purple, brown, gray # Prefix the color with bold_ to use bold style/light color. # # Example: # To print word "Hello" in bold blue: # _c bold_blue "Hello" # # To print text with only one word colored: # echo "Hello, $(c green world)." # # To do: # Support for background color, underline, etc. # # Reference: # Colours, http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html # _c() { color_name="${1}" shift text="${*}" esq="\033[" r="${esq}0m" # r for reset case "${color_name}" in bold_*) color="1;";; *) color="0;";; esac case "${color_name}" in *black) color="${color}30";; *blue) color="${color}34";; *green) color="${color}32";; *cyan) color="${color}36";; *red) color="${color}31";; *purple) color="${color}35";; *brown) color="${color}33";; *gray) color="${color}37";; esac color="${esq}${color}m" printf "${color}%s${r}" "${text}" }