
	read -s -n1 -t 2 esc < /dev/tty # read ^G suffix

	if $decimal
	then
		eval $( echo $colour | sed -e "s@rgb:\(..\)../\(..\)../\(..\)..@printf '$3=%d,%d,%d' 0x\1 0x\2 0x\3@" -e t -e "s,^,printf $3=," )
		echo
	else
		# 4-digit hex
		echo $3=$colour
		# 2-digit hex
		#echo $3=$colour | sed -e "s,rgb:\(..\)../\(..\)../\(..\)..,rgb:\1/\2/\3,"
	fi
}

conftheme() {
	if [ `uname` = "Linux" ] && type wslpath 2> /dev/null 1>&2
	then
		themefile=`wslpath -ma "$1"`
	elif type cygpath 2> /dev/null 1>&2
	then
		themefile=`cygpath -wa "$1"`
	else
		echo "cannot save to config file in this system environment"
		exit
	fi
	if [ `uname` = "Linux" ] && type wslpath 1>&2
	then
		ls "$APPDATA/mintty/config"
	elif type cygpath 1>&2
	then
		ls ~/.minttyrc ~/.config/mintty/config "$APPDATA/mintty/config" /etc/minttyrc
	fi 2> /dev/null |
	while read conffile
	do	if [ -w "$conffile" ]
		then
			newconf=/tmp/minttyrc.$$
			# create new config file with modified entry
			sed -n -e "/^ThemeFile[	 ]*=/ q" -e p "$conffile" > "$newconf"
			echo "ThemeFile=$themefile" >> "$newconf"
			sed -e "1,/^ThemeFile[	 ]*=/ d" "$conffile" >> "$newconf"
			# copy new config file back
			/bin/cp "$newconf" "$conffile"
			/bin/rm "$newconf"
			# feedback
			echo "saved theme '$themefile'"
			echo "in config file '$conffile'"
			return
		fi
	done
}

decimal=false
show2=false
case "$1" in
-d|--decimal)
	decimal=true
	shift;;
esac

case `uname` in
Linux)	if [ -n "$APPDATA" ]
	then	APPDATA=`wslpath "$APPDATA"`
	else	echo APPDATA not set >&2
		exit
	fi;;
esac

case "$1" in
-h|--help|'')
	help
	;;
-l|--list)
	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 "