%%;*}"
	rest="${da#*;}"
	vers="${rest%%;*}"
	rest="${rest#*;}"
	rest="${rest%%c}"
	set - $type $vers $rest
;;
esac
echo $1
}

showtheme() {
	theme="$1"
	export theme
	sed \
	    -e 's/^\(ForegroundColour\)[ 	]*=/\1=/' \
	    -e 's/^\(BackgroundColour\)[ 	]*=/\1=/' \
	    -e 's/^\(CursorColour\)[ 	]*=/\1=/' \
	    -e 's/^\(Black\)[ 	]*=/\1=/' \
	    -e 's/^\(Red\)[ 	]*=/\1=/' \
	    -e 's/^\(Green\)[ 	]*=/\1=/' \
	    -e 's/^\(Yellow\)[ 	]*=/\1=/' \
	    -e 's/^\(Blue\)[ 	]*=/\1=/' \
	    -e 's/^\(Magenta\)[ 	]*=/\1=/' \
	    -e 's/^\(Cyan\)[ 	]*=/\1=/' \
	    -e 's/^\(White\)[ 	]*=/\1=/' \
	    -e 's/^\(BoldBlack\)[ 	]*=/\1=/' \
	    -e 's/^\(BoldRed\)[ 	]*=/\1=/' \
	    -e 's/^\(BoldGreen\)[ 	]*=/\1=/' \
	    -e 's/^\(BoldYellow\)[ 	]*=/\1=/' \
	    -e 's/^\(BoldBlue\)[ 	]*=/\1=/' \
	    -e 's/^\(BoldMagenta\)[ 	]*=/\1=/' \
	    -e 's/^\(BoldCyan\)[ 	]*=/\1=/' \
	    -e 's/^\(BoldWhite\)[ 	]*=/\1=/' \
	    -e 't ok' -e d -e ': ok' -e 's/[ 	]//g' \
	    "$1" |
	(
cat <<\/EOS
xrgb() {
	sed -e "s,	, ,g" /usr/share/X11/rgb.txt |
	sed -e "s/ *\([0-9][0-9]*\) *\([0-9][0-9]*\) *\([0-9][0-9]*\) *$1 *$/\1;\2;\3/" -e t -e d
}
ForegroundColour=39
BackgroundColour=49
CursorColour=49
Black=40
Red=41
Green=42
Yellow=43
Blue=44
Magenta=45
Cyan=46
White=47
BoldBlack=100
BoldRed=101
BoldGreen=102
BoldYellow=103
BoldBlue=104
BoldMagenta=105
BoldCyan=106
BoldWhite=107
/EOS
	# transform colour specs:
	# d,d,d
	#	d;d;d
	# #RRGGBB
	#	0xRR
	# rgb:RR/GG/BB
	#	0xRR
	# rgb:RRRR/GGGG/BBBB
	#	0xRR
	# cmy:C.C/M.M/Y.Y
	#	r = (1 - c) * 255;
	#	g = (1 - m) * 255;
	#	b = (1 - y) * 255;
	# cmyk:C.C/M.M/Y.Y/K.K
	#	r = (1 - c) * (1 - k) * 255;
	#	g = (1 - m) * (1 - k) * 255;
	#	b = (1 - y) * (1 - k) * 255;
	# X11 color names
	sed -e 's%=\([0-9]*\),\([0-9]*\),\([0-9]*\)%="\1;\2;\3"%' \
	    -e 's%=#\([0-9A-Fa-f][0-9A-Fa-f]\)\([0-9A-Fa-f][0-9A-Fa-f]\)\([0-9A-Fa-f][0-9A-Fa-f]\)%="$((0x\1));$((0x\2));$((0x\3))"%' \
	    -e 's%=rgb:\([0-9A-Fa-f][0-9A-Fa-f]\)/\([0-9A-Fa-f][0-9A-Fa-f]\)/\([0-9A-Fa-f][0-9A-Fa-f]\)%="$((0x\1));$((0x\2));$((0x\3))"%' \
	    -e 's%=rgb:\([0-9A-Fa-f][0-9A-Fa-f]\)[0-9A-Fa-f][0-9A-Fa-f]/\([0-9A-Fa-f][0-9A-Fa-f]\)[0-9A-Fa-f][0-9A-Fa-f]/\([0-9A-Fa-f][0-9A-Fa-f]\)[0-9A-Fa-f][0-9A-Fa-f]%="$((0x\1));$((0x\2));$((0x\3))"%' \
	    -e '/=cmy/ s%\([01]\)\.\([0-9]*\)%\1.\2000%g' \
	    -e '/=cmy/ s%\([01]\)\.\([0-9][0-9][0-9]\)[0-9]*%\1\2%g' \
	    -e '/=cmy:/ s%cmy:\([0-9/]*\)%cmyk:\1/0000%' \
	    -e 's%=cmyk:\([01][0-9][0-9][0-9]\)/\([01][0-9][0-9][0-9]\)/\([01][0-9][0-9][0-9]\)/\([01][0-9][0-9][0-9]\)%=cmyk:"$(( (1000 - \1) * (1000 - \4) * 255 / 1000000 ));$(( (1000 - \2) * (1000 - \4) * 255 / 1000000 ));$(( (1000 - \3) * (1000 - \4) * 255 / 1000000 ))"%' \
	    -e '/=cmyk:/ s%\([^0-9]\)0*\([0-9]\)%\1\2%g' -e 's%=cmyk:%=%' \
	    -e 's%=\([a-zA-Z][a-zA-Z ]*\)%=`xrgb "\1"`%' \
	    -e 't ok' -e d -e ': ok' -e 's%="%="48;2;%'
if $show2
then cat <<\/EOS
	echo -en "\e[37;${Black}mblk"
	echo -en "\e[30;${Red}mred"
	echo -en "\e[30;${Green}mgrn"
	echo -en "\e[30;${Yellow}mylw"
	echo -en "\e[30;${Blue}mblu"
	echo -en "\e[30;${Magenta}mmag"
	echo -en "\e[30;${Cyan}mcyn"
	echo -en "\e[30;${White}mwht"
	echo -en "\e[39;${CursorColour}m "
	echo -e "\e[m${theme}"
	echo -en "\e[37;${BoldBlack}mBLK"
	echo -en "\e[30;${BoldRed}mRED"
	echo -en "\e[30;${BoldGreen}mGRN"
	echo -en "\e[30;${BoldYellow}mYLW"
	echo -en "\e[30;${BoldBlue}mBLU"
	echo -en "\e[30;${BoldMagenta}mMAG"
	echo -en "\e[30;${BoldCyan}mCYN"
	echo -en "\e[30;${BoldWhite}mWHT"
	echo -en "\e[39;${CursorColour}m "
	echo -e "\e[${ForegroundColour};${BackgroundColour}m${theme}\e[m"
/EOS
else cat <<\/EOS
	echo -en "\e[${ForegroundColour};${BackgroundColour}mfgbg"
	echo -en "\e[39;${CursorColour}mC"
	echo -en "\e[37;${Black}mbk"
	echo -en "\e[30;${Red}mrd"
	echo -en "\e[30;${Green}mgn"
	echo -en "\e[30;${Yellow}myl"
	echo -en "\e[30;${Blue}mbl"
	echo -en "\e[30;${Magenta}mmg"
	echo -en "\e[30;${Cyan}mcy"
	echo -en "\e[30;${White}mwh"
	echo -en "\e[37;${BoldBlack}mBK"
	echo -en "\e[30;${BoldRed}mRD"
	echo -en "\e[30;${BoldGreen}mGN"
	echo -en "\e[30;${BoldYellow}mYL"
	echo -en "\e[30;${BoldBlue}mBL"
	echo -en "\e[30;${BoldMagenta}mMG"
	echo -en "\e[30;${BoldCyan}mCY"
	echo -en "\e[30;${BoldWhite}mWH"
	echo -e "\e[m $theme"
/EOS
fi
	) | sh
}

showthemes() {
	for confdir in ~/.mintty ~/.config/mintty "$APPDATA"/mintty /usr/share/mintty
	do	if [ -d "$confdir/themes" -a -x "$confdir/themes"  -a -r "$confdir/themes" ]
		then	echo "