π KISS: See
kiss-colors.sh
for a simpler version π
$(c <flags>)
inside an echo -e
or printf
Or $(c)
to reset
cecho <flags> <text>
is a shortcut for echo -e "$(c <flags>)<text>$(c)"
βββββββββ¬βββββββββββββββββ¬ββββββββββββββββββ βββββββββ¬ββββββββββββββββββ¬ββββββββ
β Fg/Bg β Color β Octal β β Code β Style β Octal β
βββββββββΌβββββββββββββββββΌββββββββββββββββββ€ βββββββββΌββββββββββββββββββΌββββββββ€
β K/k β Black β \e[ + 3/4 + 0m β β s/S β Bold (strong) β \e[1m β
β R/r β Red β \e[ + 3/4 + 1m β β d/D β Dim β \e[2m β
β G/g β Green β \e[ + 3/4 + 2m β β i/I β Italic β \e[3m β
β Y/y β Yellow β \e[ + 3/4 + 3m β β u/U β Underline β \e[4m β
β B/b β Blue β \e[ + 3/4 + 4m β β f/F β Blink (flash) β \e[5m β
β M/m β Magenta β \e[ + 3/4 + 5m β β n/N β Negative β \e[7m β
β C/c β Cyan β \e[ + 3/4 + 6m β β h/H β Hidden β \e[8m β
β W/w β White β \e[ + 3/4 + 7m β β t/T β Strikethrough β \e[9m β
βββββββββ΄βββββββββββββββββ΄ββββββββββββββββββ€ βββββββββΌββββββββββββββββββΌββββββββ€
β High intensity β \e[ + 9/10 + *m β β 0 β Reset β \e[0m β
ββββββββββββββββββββββββββ΄ββββββββββββββββββ βββββββββ΄ββββββββββββββββββ΄ββββββββ
Uppercase = Reset a style: \e[2*m
The single parameter of the function is composed of one or several 1-character flags.
By convention in this order: reset, formats, foreground, background.
Or in regex language: 0?S?[sdiufn-]*[KRGYBMCW]?[krgybmcw]?
- Reset must come before the others⦠or it will undo immediately the formatting! So
$(c 0s)
and not$(c s0)
. - @TODO:
h
for high intensity is not yet implemented. - Quite slow π
printf "$(c sW)Bold white$(c) and normal"
echo -e "Normal text⦠$(c sRy)BOLD red text on yellow background⦠$(c w)now on white background⦠$(c 0u) reset and underline⦠$(c) and back to normal."
cecho Wb "White text on blue background"
- Bash tips: Colors and formatting (ANSI/VT100 Control sequences)
- Very complete explanations on StackOverflow
- Coloring functions
Licensed under the MIT License.