#!/bin/sh -

# viewcolorrc - colorize a GNU-ls color configuration file with itself
# Steve Kinzler, steve@kinzler.com, Nov 98/Jun 05
# https://kinzler.com/me/home.html#unixcfg

case "$1" in
-h)	echo "usage: $0 [ dircolors_file ]" 1>&2; exit 1;;
esac

expand ${1+"$@"} | perl -ne '
	$chop = chop;
	($on, $off) = (/^(#\d+#)?[^#]+\s((\d\d;)*\d\d)\s*(#.*)?$/)
				? ("\e[$2m", "\e[00m") : ("", "");
	print $on, $_, $off, $chop;'
