Skip to content

Instantly share code, notes, and snippets.

@viega
Created September 2, 2023 16:08
Show Gist options
  • Save viega/f3ad2993597619d3323e43f51448e9e4 to your computer and use it in GitHub Desktop.
Save viega/f3ad2993597619d3323e43f51448e9e4 to your computer and use it in GitHub Desktop.
My bash function(s) for colorizing test in shell scripts.
function color {
case $1 in
black) CODE=0 ;;
red) CODE=1 ;; RED) CODE=9 ;;
green) CODE=2 ;; GREEN) CODE=10 ;;
yellow) CODE=3 ;; YELLOW) CODE=11 ;;
blue) CODE=4 ;; BLUE) CODE=12 ;;
magenta) CODE=5 ;; MAGENTA) CODE=13 ;;
cyan) CODE=6 ;; CYAN) CODE=14 ;;
white) CODE=7 ;; WHITE) CODE=15 ;;
grey) CODE=8 ;; *) CODE=$1 ;;
esac
shift
echo -n $(tput setaf ${CODE})$@$(tput op)
}
function colorln {
echo $(color $@)
}
@viega
Copy link
Author

viega commented Sep 2, 2023

Can do things like:

colorln CYAN This part is bold cyan $(color RED and this part is bold red.)

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