#!/bin/bash # I wrote this so I could see the color numbers I wanted to use when coding on a terminal. # It runs threw all the basics, 8 colors for normal terminals and 256 for the ones that # support it. The determination of support is the $TERM varible ending with '-256color'. # shellcheck disable=SC2034 tput smcup # save the terminal screen clear r(){ # Random color function just because it is fun to do! # -256color [[ $TERM = *256color ]] && NUM=$((1 + RANDOM % 256)) # or not [[ $TERM != *256color ]] && NUM=$(( RANDOM % 8)) echo -n "$(tput setaf $NUM)" } if [[ $TERM = *256color ]] then # -256color echo "Foreground: tput setf # (or 'setaf' for ANSI)" for((n=1; n<=256; n++)) { echo -n "$(tput setaf $n)$n " } echo "$(r)Complete!" tput sgr0 echo "Background: tput setb # (or 'setaf' for ANSI)" for((n=1; n<=256; n++)) { echo -n "$(tput setab $n)$n " } echo "$(r)Complete!" else # 8 color echo "Foreground: tput setf # (or 'setaf' for ANSI)" for((n=0; n<=7; n++)) { echo -n "$(tput setaf $n)$n " } echo "$(r)Complete!" tput sgr0 echo "Background: tput setb # (or 'setaf' for ANSI)" for((n=0; n<=7; n++)) { echo -n "$(tput setb $n)$n " } tput sgr0 echo "$(r)Complete!" fi tput sgr0 echo "$(tput smul)Underline on: tput smul" echo "$(tput rmul)Underline off: tput rmul" echo "$(tput bold)Bold on: tput bold";tput sgr0 echo "$(tput dim)Dim on: tput dim" echo "$(tput rev)Reverse palette: tput rev" echo "$(tput sgr0)Revert all attribute changes: tput sgr0" # shellcheck disable=SC2162 read -n 1 -p "Hit any key to continue" x tput rmcup # restore terminal screen