Skip to content

Instantly share code, notes, and snippets.

@kodie
Created August 25, 2016 16:51
Show Gist options
  • Save kodie/203c732643bb81a5e224ad82fc8636fc to your computer and use it in GitHub Desktop.
Save kodie/203c732643bb81a5e224ad82fc8636fc to your computer and use it in GitHub Desktop.
Functions to display styled text
function txtStyle {
local color
local background
local style
local output
case "$1" in
"black") color="30" ;;
"red") color="31" ;;
"green") color="32" ;;
"yellow") color="33" ;;
"blue") color="34" ;;
"magenta") color="35" ;;
"cyan") color="36" ;;
"white") color="37" ;;
*) color="37" ;;
esac
case "$2" in
"black") background="40" ;;
"red") background="41" ;;
"green") background="42" ;;
"yellow") background="43" ;;
"blue") background="44" ;;
"magenta") background="45" ;;
"cyan") background="46" ;;
"white") background="47" ;;
*) background="40" ;;
esac
case "$3" in
"normal") style="0" ;;
"bold") style="1" ;;
"underline") style="4" ;;
"blink") style="5" ;;
*) style="0" ;;
esac
output="\e["$style";"$color";"$background"m"
echo $output
}
function txt {
local color=$(txtStyle $2 $3 $4)
local def=$(txtStyle)
printf "$color$1$def\n"
}
txt "Here is some styled text!" cyan magenta bold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment