#!/bin/bash # examples: # echo "$(str_color cyan "This") is a $(str_color red "$(str_underline "test")")!" # bold is str_mod 1 21 but the 21 (reset) doesn't work in my environment # blink is str_mod 5 25 # style convenience handlers function str_mod() { echo -en "\e[${1}m${3}\e[${2}m"; } function str_underline() { str_mod 4 24 "${1}"; } function str_invert() { str_mod 7 27 "${1}"; } function str_color() { case "${1}" in "black") str_mod 30 39 "${2}" ;; "red") str_mod 31 39 "${2}" ;; "green") str_mod 32 39 "${2}" ;; "yellow") str_mod 33 39 "${2}" ;; "blue") str_mod 34 39 "${2}" ;; "magenta") str_mod 35 39 "${2}" ;; "cyan") str_mod 36 39 "${2}" ;; "lgrey") str_mod 37 39 "${2}" ;; "dgrey") str_mod 90 39 "${2}" ;; "lred") str_mod 31 39 "${2}" ;; "lgreen") str_mod 32 39 "${2}" ;; "lyellow") str_mod 33 39 "${2}" ;; "lblue") str_mod 34 39 "${2}" ;; "lmagenta") str_mod 35 39 "${2}" ;; "lcyan") str_mod 36 39 "${2}" ;; "white") str_mod 37 39 "${2}" ;; *) echo "${2}" ;; esac }