I played a bit with the prompt to archive similar behavior like the bash prompt.
Code: Select all
export PS1="Time \$(date --iso=sec)"
This exact example can be solved by simply use set "prompt=Time $T"
But currently, it's not possible to execute any program or even to show the current value of a variable
I've build a partial solution, but I need to manually press <ENTER>
Code: Select all
@echo off
REM *** Trampoline jump for function calls of the form ex. "C:\:function:\..\MyBatchFile.bat"
FOR /F "tokens=3 delims=:" %%L in ("%~0") DO goto :%%L
for /f "delims=" %%C in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x1B"'
) do set "esc=%%C"
for /f "delims=" %%C in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x08"'
) do set "BS=%%C"
doskey %esc%[1;1R="%~d0\:action:\..\%~pnx0" arg1
REM *** doskey /macros
goto :set_prompt
exit /b
:action
for /f "delims=" %%C in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x1B"'
) do set "esc=%%C"
for /f "delims=" %%C in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x08"'
) do set "BS=%%C"
REM *** Remove the "^[[1;1R" string and add custom data
set /a count+=1
set "CUSTOM_DATA=[%count%] ^>"
echo %esc%[u%esc%[K%CUSTOM_DATA%
rem ###%TIME% %0 %*
REM *** uncomment the exit /b for simpler testing
REM *** exit /b
:set_prompt
prompt $e[s$e[H$e[6n$e[u$P$S$e[s
This goes directly to the input buffer, it's treated like keyboard input.
To get always the same result, I use the "$e[H" sequence to bring the cursor to the home position (1,1).
So the answer to "ESC[6n" is always "ESC[1,1R", in the console you see "^[[1,1R"
I defined a doskey macro with the name "^[[1,1R" to fetch exactly this sequence.
In action, it looks like
Code: Select all
C:\Users\jeb [21] >
C:\Users\jeb [22] >
C:\Users\jeb [23] >
C:\Users\jeb [24] >
C:\Users\jeb ^[[1;1R
Any ideas?