From 5bdfa20d90d20387c35db163fe10f992a1a3d6a1 Mon Sep 17 00:00:00 2001 From: Abderrahmane TAHRI JOUTI <302837+atahrijouti@users.noreply.github.com> Date: Tue, 26 Sep 2023 11:31:48 +0200 Subject: [PATCH 1/3] exit lf not the cmd --- etc/lfcd.cmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/lfcd.cmd b/etc/lfcd.cmd index 1d950981..473af3e7 100644 --- a/etc/lfcd.cmd +++ b/etc/lfcd.cmd @@ -7,9 +7,9 @@ rem You need to put this file to a folder in %PATH% variable. set tmpfile="%tmp%\lf.%random%.tmp" if exist %tmpfile% goto:tmploop lf -last-dir-path=%tmpfile% %* -if not exist %tmpfile% exit +if not exist %tmpfile% exit 1 set /p dir=<%tmpfile% del /f %tmpfile% -if not exist "%dir%" exit -if "%dir%" == "%cd%" exit +if not exist "%dir%" exit 1 +if "%dir%" == "%cd%" exit 1 cd /d "%dir%" From 83919cbc0d97d2fe10979ae1e5af63732567ffaa Mon Sep 17 00:00:00 2001 From: Abderrahmane TAHRI JOUTI <302837+atahrijouti@users.noreply.github.com> Date: Tue, 26 Sep 2023 11:39:57 +0200 Subject: [PATCH 2/3] exit successfully --- etc/lfcd.cmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/lfcd.cmd b/etc/lfcd.cmd index 473af3e7..e17d378d 100644 --- a/etc/lfcd.cmd +++ b/etc/lfcd.cmd @@ -7,9 +7,9 @@ rem You need to put this file to a folder in %PATH% variable. set tmpfile="%tmp%\lf.%random%.tmp" if exist %tmpfile% goto:tmploop lf -last-dir-path=%tmpfile% %* -if not exist %tmpfile% exit 1 +if not exist %tmpfile% exit 0 set /p dir=<%tmpfile% del /f %tmpfile% -if not exist "%dir%" exit 1 -if "%dir%" == "%cd%" exit 1 +if not exist "%dir%" exit 0 +if "%dir%" == "%cd%" exit 0 cd /d "%dir%" From 5aa07b4429bff173a3419d0d82af6763665ad77e Mon Sep 17 00:00:00 2001 From: Abderrahmane TAHRI JOUTI <302837+atahrijouti@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:47:44 +0200 Subject: [PATCH 3/3] use -print-last-dir --- etc/lfcd.cmd | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/etc/lfcd.cmd b/etc/lfcd.cmd index e17d378d..ce23dd64 100644 --- a/etc/lfcd.cmd +++ b/etc/lfcd.cmd @@ -3,13 +3,4 @@ rem Change working dir in cmd.exe to last dir in lf on exit. rem rem You need to put this file to a folder in %PATH% variable. -:tmploop -set tmpfile="%tmp%\lf.%random%.tmp" -if exist %tmpfile% goto:tmploop -lf -last-dir-path=%tmpfile% %* -if not exist %tmpfile% exit 0 -set /p dir=<%tmpfile% -del /f %tmpfile% -if not exist "%dir%" exit 0 -if "%dir%" == "%cd%" exit 0 -cd /d "%dir%" +for /f "usebackq tokens=*" %%d in (`lf -print-last-dir %*`) do cd %%d