diff --git a/bin/j.bat b/bin/j.bat index 602344c..77925c9 100644 --- a/bin/j.bat +++ b/bin/j.bat @@ -1,15 +1,21 @@ @echo off +setlocal EnableDelayedExpansion echo %*|>nul findstr /rx \-.* if ERRORLEVEL 1 ( - for /f %%G in ('python %~dp0\autojump %*') do set new_path=%%G - if exist %new_path%/nul ( - cd %new_path% + for /f %%i in ('python %~dp0\autojump %*') do set new_path=%%i + if exist !new_path!\nul ( + echo !new_path! + pushd !new_path! + REM endlocal is necessary so that we can change directory for outside of this script + REM but will automatically popd. We mush pushd twice to work around this. + pushd !new_path! + endlocal + popd ) else ( echo autojump: directory %* not found echo try `autojump --help` for more information ) - echo %new_path% ) else ( python %~dp0\autojump %* ) \ No newline at end of file diff --git a/bin/jo.bat b/bin/jo.bat index f952d1f..1bb2485 100644 --- a/bin/jo.bat +++ b/bin/jo.bat @@ -1,15 +1,15 @@ @echo off +setlocal EnableDelayedExpansion echo %*|>nul findstr /rx \-.* if ERRORLEVEL 1 ( - for /f %%G in ('python %~dp0\autojump %*') do set new_path=%%G - if exist %new_path%/nul ( - start %new_path% + for /f %%i in ('python %~dp0\autojump %*') do set new_path=%%i + if exist !new_path!\nul ( + start !new_path! ) else ( echo autojump: directory %* not found echo try `autojump --help` for more information ) - echo %new_path% ) else ( python %~dp0\autojump %* ) \ No newline at end of file