#!/bin/sh

IFS=
alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ - 1234567890 - abcdefghijklmnopqrstuvwxyz";
reset=$(tput sgr0);

for((i = 0; i <= 256; i++)); do
	colour=$(tput setaf $i);
	space=" ";
	[ $i -lt 10 ] && { space="  ";   };
	[ $i -gt 99 ] && { space=""; };
	echo "${reset}${space}$i   ${colour}${alphabet}";
done;

echo $reset;

#!/bin/sh

IFS=
alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ - 1234567890 - abcdefghijklmnopqrstuvwxyz";
reset=$(tput sgr0);
max=256


# Show only the first 16 colours by default
count=15

# Parse any options we were given
while getopts alc: option; do
	case $option in
	a)	count=$max				;;	# Show all colours
	l)	count=$max				;;	# Synoynm for -a: displays a long rainbow
	c)	count=$((OPTARG - 1))	;;	# Displays an arbitrary number of colours
	esac
done;


[ $count -le 0 ] && { count=0; }

for((i = 0; i <= $count; i++)); do
	colour=$(tput setaf $i);
	space=" ";
	[ $i -lt 10 ] && { space="  "; }
	[ $i -gt 99 ] && { space=""; }
	echo "${reset}${space}$i   ${colour}${alphabet}";
done;

echo $reset;

Add length-handling to xterm-colour lister
Add length-handling to xterm-colour lister

The utility now only lists 16 colours by default, with the full spectrum
accessed by passing either -a ("All") or -l ("Long"). Custom lengths can
can also be used by setting the -c ("Count") option.

    $ rainbow -a      # Generates a 256-colour list
    $ rainbow -l      # Same as above
    $ rainbow -c 128  # Generates a 128-colour list
