Skip to content

Instantly share code, notes, and snippets.

@peterrus
Last active January 21, 2022 02:32
Show Gist options
  • Save peterrus/f3dd5142720f6c80ac980e286d52cfad to your computer and use it in GitHub Desktop.
Save peterrus/f3dd5142720f6c80ac980e286d52cfad to your computer and use it in GitHub Desktop.
Simple status colors in Bash with tput
# Colors and fonts
# Only loaded on interactive terminals
if [ -t 0 ]; then
T_ERROR=$(tput setaf 7; tput setab 1)
T_INFO=$(tput setaf 7; tput setab 4)
T_WARNING=$(tput setaf 0; tput setab 3)
T_SUCCESS=$(tput setaf 0; tput setab 2)
T_BOLD=$(tput bold)
T_RESET=$(tput sgr0)
fi
# End colors and fonts
echo "${T_INFO}Informative text.${T_RESET}"
echo "${T_ERROR}Stuff is hitting the ${T_BOLD}proverbial${T_RESET}${T_ERROR} fan!${T_RESET}"
echo "${T_WARNING}This is a warning!${T_RESET}"
echo "${T_SUCCESS}Everything is alright...${T_RESET}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment