@echo off
rem  tk from PowerShell or cmd. The script itself is bash; this only finds a bash and hands it over.
rem
rem  Two things bite here, and both did on 30 September 2026:
rem    - "bash" on a Windows PATH can be WSL bash, which cannot open D: paths at all, so a Windows bash
rem      (Cygwin, or Git for Windows) is preferred where one is installed; plain "bash" is the last resort.
rem    - a Windows path with backslashes, passed as the script name, fails to open ("No such file or
rem      directory"), so this changes into the folder first and runs ./tk, a name that needs no conversion.
rem  Keep CRLF line endings in this file: cmd.exe mis-parses a .cmd saved with LF only.
setlocal
set "SH="
for %%B in ("%SystemDrive%\cygwin64\bin\bash.exe" "%ProgramFiles%\Git\bin\bash.exe" "%LOCALAPPDATA%\Programs\Git\bin\bash.exe") do (
    if not defined SH if exist "%%~B" set "SH=%%~B"
)
if not defined SH set "SH=bash"
pushd "%~dp0"
"%SH%" ./tk %*
set "RC=%ERRORLEVEL%"
popd
exit /b %RC%
