@echo off
rem Invoke mined in a newly started MinTTY terminal.

rem Configure config file:
set noconf=
set confdir=%HOME%
if exist "%confdir%\.minttyrc" goto confok
set confdir=%USERPROFILE%
if exist "%confdir%\.minttyrc" goto confok
set confdir=.
if exist "%confdir%\.minttyrc" goto confok
set noconf=rem
:confok
set conf="%confdir%\.minttyrc.win"

rem Configure UTF-8
set LC_ALL=en_US.UTF-8
echo Codepage=UTF-8 > %conf%

rem Select font
set font=Lucida Console
rem ...?

rem give Windows "find.exe" precedence, provide temp. scripts
PATH %windir%\system32;%windir%\command;%PATH%;%TEMP%

set TMP=%TEMP%

rem Acquire and configure Windows system color settings
rem reg query "HKEY_CURRENT_USER\Control Panel\Colors" /v WindowText | sed -e "s/.*	//" -e t -e d | sed -e "s/ /,/g" -e "s/^/ForegroundColour=/" >> %conf%
rem reg query "HKEY_CURRENT_USER\Control Panel\Colors" /v Window | sed -e "s/.*	//" -e t -e d | sed -e "s/ /,/g" -e "s/^/BackgroundColour=/" >> %conf%
reg query "HKEY_CURRENT_USER\Control Panel\Colors" /v WindowText | find "Window" > %TMP%\winedfg.bat
reg query "HKEY_CURRENT_USER\Control Panel\Colors" /v Window | find "Window" > %TMP%\winedbg.bat
echo echo ForegroundColour=%%2,%%3,%%4 > %TMP%\WindowText.bat
echo echo BackgroundColour=%%2,%%3,%%4 > %TMP%\Window.bat
call %TMP%\winedfg.bat >> %conf%
call %TMP%\winedbg.bat >> %conf%

rem Disable scrollbar and interfering shortcuts
echo Scrollbar=0 >> %conf%
echo WindowShortcuts=0 >> %conf%
echo EditShortcuts=0 >> %conf%
echo BoldAsBright=0 >> %conf%

rem Append standard configuration if found
rem if exist "%confdir%\.minttyrc" type "%confdir%\.minttyrc" >> %conf%
%noconf% type "%confdir%\.minttyrc" | find /V "Codepage=" | find /V "ForegroundColour=" | find /V "BackgroundColour=" | find /V "Scrollbar=" | find /V "WindowShortcuts=" | find /V "EditShortcuts=" | find /V "BoldAsBright=" >> %conf%

rem Repeat overriding configuration to make sure it is applied
rem echo Codepage=UTF-8 >> %conf%
rem call %TMP%\winedfg.bat >> %conf%
rem call %TMP%\winedbg.bat >> %conf%
rem echo Scrollbar=0 >> %conf%
rem echo WindowShortcuts=0 >> %conf%
rem echo EditShortcuts=0 >> %conf%
rem echo BoldAsBright=0 >> %conf%

rem Start mintty
start mintty.exe -c %conf% -e /usr/bin/mined %1 %2 %3 %4 %5 %6 %7 %8 %9
