Skip to content

Instantly share code, notes, and snippets.

@tmlbl
Created September 15, 2019 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmlbl/383fa70a3c610394721319cbaa2e93c1 to your computer and use it in GitHub Desktop.
Save tmlbl/383fa70a3c610394721319cbaa2e93c1 to your computer and use it in GitHub Desktop.
# Bash snippet for printing things in color
# Examples:
# in_color $GREEN "hello\n"
# in_color $RED "uh oh\n" $BOLD
# ok=$(in_color $GREEN OK $BOLD)
# echo "[ $ok ] Things are good"
__COLOR_RESET='\033[0m'
BLACK=30
RED=31
GREEN=32
ORANGE=33
BLUE=34
PURPLE=35
CYAN=36
GRAY=37
BOLD=1
in_color() {
code=$1
message=$2
bold=$3
if [ "$bold" = "" ]; then
bold="0"
fi
printf "\033[$bold;${code}m$message$__COLOR_RESET"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment