diff --git a/z.cmd b/z.cmd index f632aea..8d64f7f 100644 --- a/z.cmd +++ b/z.cmd @@ -98,6 +98,11 @@ for /f "delims=" %%i in ('cd') do set "PWD=%%i" if /i "%RunMode%"=="-n" ( for /f "delims=" %%i in ('call "%LuaExe%" "%LuaScript%" --cd %MatchType% %StrictSub% %InterMode% %*') do set "NewPath=%%i" + if "!NewPath!"=="" ( + set NewPath=%1 + call :normalizepath !NewPath! + set NewPath=!retval! + ) if not "!NewPath!"=="" ( if exist !NewPath!\nul ( if /i not "%_ZL_ECHO%"=="" ( @@ -121,8 +126,16 @@ rem -- directory without leaking a pushd. popd setlocal set NewPath=%CD% -endlocal & popd & cd /d "%NewPath%" +set "CDCmd=cd /d" +if /i not "%_ZL_CD%"=="" ( + set "CDCmd=%_ZL_CD%" +) +endlocal & popd & %CDCmd% "%NewPath%" :end echo. +exit /B +:normalizepath +set retval=%~f1 +exit /B diff --git a/z.lua b/z.lua index ca912ef..b2b8803 100755 --- a/z.lua +++ b/z.lua @@ -2544,6 +2544,11 @@ if /i "%1"=="" ( for /f "delims=" %%i in ('cd') do set "PWD=%%i" if /i "%RunMode%"=="-n" ( for /f "delims=" %%i in ('call "%LuaExe%" "%LuaScript%" --cd %MatchType% %StrictSub% %InterMode% %*') do set "NewPath=%%i" + if "!NewPath!"=="" ( + set NewPath=%1 + call :normalizepath !NewPath! + set NewPath=!retval! + ) if not "!NewPath!"=="" ( if exist !NewPath!\nul ( if /i not "%_ZL_ECHO%"=="" ( @@ -2563,8 +2568,16 @@ goto end popd setlocal set "NewPath=%CD%" -endlocal & popd & cd /d "%NewPath%" +set "CDCmd=cd /d" +if /i not "%_ZL_CD%"=="" ( + set "CDCmd=%_ZL_CD%" +) +endlocal & popd & %CDCmd% "%NewPath%" :end +exit /B +:normalizepath +set retval=%~f1 +exit /B ]]