Code: Select all
@echo on
@setlocal EnableDelayedExpansion
for /f "tokens=*" %%L in (.git/logs/HEAD) do (
set VAR = "%TWO%"
set TWO = %%L
if "%%L" == "" (
for /f "tokens=5* delims= " %%I in (%VAR%) do (
set VONE = %VTWO%
set VTWO = %%I
if "%%I" == "" echo (
"#include \"CoditBuild.h\""
"unsigned long CODIT_COMMIT = %VONE%;"
) >src/CoditCommit.c
)
)
)
@endlocal
:exit
And here is my output:
Code: Select all
p:\Git\Codit>test.bat
p:\Git\Codit>for /F "tokens=*" %L in (.git/logs/HEAD) do (
set VAR = echo ""
set TWO = %L
if "%L" == "" (for /F "tokens=5* delims= " %I in ((null)) do (
set VONE = echo
set VTWO = %I
if "%I" == "" echo (
"#pragma once"
"#define CODIT_COMMIT "
) 1>CoditCommit.h )
)
p:\Git\Codit>(
set VAR = echo ""
set TWO = 0000000000000000000000000000000000000000 9b67a08ea9bd212d54da1ab734fa3d6c16d322eb
if "0000000000000000000000000000000000000000 9b67a08ea9bd212d54da1ab734fa3d6c16d322eb" == "" (for /F "tokens=5* delims= " %I in ((null)) do (
set VONE = echo
set VTWO = %I
if "%I" == "" echo (
"#pragma once"
"#define CODIT_COMMIT "
) 1>CoditCommit.h )
)
p:\Git\Codit>(
set VAR = echo ""
set TWO = 9b67a08ea9bd212d54da1ab734fa3d6c16d322eb 1b0e2957938511dc6a4be0e0becd66cffa316a8c
if "9b67a08ea9bd212d54da1ab734fa3d6c16d322eb 1b0e2957938511dc6a4be0e0becd66cffa316a8c" == "" (for /F "tokens=5* delims= " %I in ((null)) do (
set VONE = echo
set VTWO = %I
if "%I" == "" echo (
"#pragma once"
"#define CODIT_COMMIT "
) 1>CoditCommit.h )
)
p:\Git\Codit>(
set VAR = echo ""
set TWO = 1b0e2957938511dc6a4be0e0becd66cffa316a8c c6091e54e32bbaa689a54486f74bce6fd71663c2
if "1b0e2957938511dc6a4be0e0becd66cffa316a8c c6091e54e32bbaa689a54486f74bce6fd71663c2" == "" (for /F "tokens=5* delims= " %I in ((null)) do (
set VONE = echo
set VTWO = %I
if "%I" == "" echo (
"#pragma once"
"#define CODIT_COMMIT "
) 1>CoditCommit.h )
)
p:\Git\Codit>(
set VAR = echo ""
set TWO = c6091e54e32bbaa689a54486f74bce6fd71663c2 fe55dde7818b97e3728d066bf3a9cb2060262ee0
if "c6091e54e32bbaa689a54486f74bce6fd71663c2 fe55dde7818b97e3728d066bf3a9cb2060262ee0" == "" (for /F "tokens=5* delims= " %I in ((null)) do (
set VONE = echo
set VTWO = %I
if "%I" == "" echo (
"#pragma once"
"#define CODIT_COMMIT "
) 1>CoditCommit.h )
)
p:\Git\Codit>
Not sure how dangerous it is to leave some bits of the variable contents in there so just removed them for safety's sake.
As anyone paying proper attention would have noticed by now the variables trying to capture the previous line/token are not receiving their input and since I rarely delve into batch I do not understand what I've done wrong, could someone help me understand (and if they feel like it provide a Linux & OSX alternative since I will make ones for those as well)