tput-colors (547B)
1 #!/usr/bin/env bash 2 if ! command -v tput &> /dev/null; then 3 echo "tput not installed." 4 exit 1 5 fi 6 7 if ! [[ "$1" =~ ^[0-9]+$ ]]; then 8 echo "Usage: tput-colors [number]" 9 exit 1 10 fi 11 tput init &> /dev/null 12 hr() { tput sgr0; for ((i=0; i<$(tput cols); i++)); do echo -n "#"; done; echo; } 13 hr 14 echo "Colors for tput:" 15 hr 16 if [ $# -eq 0 ]; then 17 for ((i=1; i<=$(tput colors); i++)); do 18 echo "$(tput sgr0)$i $(tput setaf $i)sample text" 19 done 20 else 21 for ((i=1; i<=$1; i++)); do 22 echo "$(tput sgr0)$i $(tput setaf $i)sample text" 23 done 24 fi 25 hr