Skip to content

Instantly share code, notes, and snippets.

@scriptum
Last active August 29, 2015 14:10
Show Gist options
  • Save scriptum/4e76c6cca895cfcbc97f to your computer and use it in GitHub Desktop.
Save scriptum/4e76c6cca895cfcbc97f to your computer and use it in GitHub Desktop.
Function to colorize bash scripts
function color() {
case $1 in
red) tput setaf 1;;
green) tput setaf 2;;
yellow) tput setaf 3;;
blue) tput setaf 4;;
purple) tput setaf 5;;
cyan) tput setaf 6;;
white) tput setaf 7;;
#bold
bold) tput bold;;
bred) tput bold; tput setaf 1;;
bgreen) tput bold; tput setaf 2;;
byellow) tput bold; tput setaf 3;;
bblue) tput bold; tput setaf 4;;
bpurple) tput bold; tput setaf 5;;
bcyan) tput bold; tput setaf 6;;
bwhite) tput bold; tput setaf 7;;
reset) tput sgr0;;
*) echo "Usage: $0 [b]{red|green|yellow|blue|purple|cyan|white}|bold|reset";;
esac
}
@Frodox
Copy link

Frodox commented Nov 24, 2014

test:

source color.sh
echo $(color blue)blue_text$(color reset)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment