I started review the code deeper and found some places for improvement. Later I found that better to rewrite it from the scratch. Perhaps i will try to do it (partially). From my perspective, there are few possible ways for evolution:
1. avoid \ with / replacement - in this case awk/find/findstr usage lowers
2. migrate heavy logic (\ with / replacement, string comparison and list rotation) to jscript/vbscript and use batch as wrapper around it
To this moment there are some small improvement.
This simplification has to do with the following example from the g.bat. This one
Code: Select all
echo "%CD%">%GTMP%\tmp-cd.dat
...
for /F %%a in (%GTMP%\tmp-cd.dat) do cd /D %%a
can be replaced bravely with:
Code: Select all
set "OLDCD=%CD%"
...
cd /d "%OLDCD%"
or this one:
There are other recommendations regarding awk/gawk usage. For example this one
Code: Select all
gawk "{gsub(/\\/,\""/\""); print}" | find /V "%" | find /V "$"
can be replaced with
explanation: if the input line $0 doesn't match % or $, replace \ with /
Code: Select all
gawk "$0 !~ /[%%$]/ { gsub(/\\/, \""/\""); print }"
explanation: if the input line $0 doesn't match % or $, replace \ with / passed as the variable s. It looks better because we avoid ugly attempts to escape double quotes within double quotes.
Code: Select all
gawk -v s="/" "$0 !~ /[%%$]/ { gsub(/\\/, s); print }"
The same result with sed in the case if you decide use it some time.
explanation: if input matches one of % or $, delete it; replace \ with / globally in other lines.
One more stuff.
Code: Select all
echo "%CD%"| gawk "{ $0=substr($0,2,length($0)-2); gsub(/\\/,\""/\"",$0); print}" >%GTMP%\go-temp1.dat
set ARG="%~1"
set ARG=%ARG:\=/%
In my opinion it could be better written as below (two last lines can be combined):
Code: Select all
cd | gawk -v s="/" "{ gsub(/\\/, s); print}" >%GTMP%\go-temp1.dat
set "ARG=%~1"
set "ARG=%ARG:\=/%"
type %GTMP%\go.dat | findstr /I /E "%ARG%[^/]*$">>%GTMP%\go-temp1.dat
I quickly reviewed g.awk script. It has many ways to improve but I am not sure that I fully understand how to modify it -- there is some specialty related to the situation:
I seem written a lot of words. Hope they were useful.