From fd2d3a0f86bcef8551bc543096ce3388b356c53e Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 21 Oct 2017 21:00:10 +0300 Subject: [PATCH] add cd scripts for cmd.exe and powershell --- etc/lfcd.cmd | 15 +++++++++++++++ etc/lfcd.ps1 | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 etc/lfcd.cmd create mode 100644 etc/lfcd.ps1 diff --git a/etc/lfcd.cmd b/etc/lfcd.cmd new file mode 100644 index 00000000..f2259006 --- /dev/null +++ b/etc/lfcd.cmd @@ -0,0 +1,15 @@ +@echo off +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 +set /p dir=<"%tmpfile%" +del /f "%tmpfile%" +if not exist "%dir%" exit +if "%dir%" == "%cd%" exit +cd "%dir%" diff --git a/etc/lfcd.ps1 b/etc/lfcd.ps1 new file mode 100644 index 00000000..0b543147 --- /dev/null +++ b/etc/lfcd.ps1 @@ -0,0 +1,15 @@ +# Change working dir in powershell to last dir in lf on exit. +# +# You need to put this file to a folder in $ENV:PATH variable. + +$tmp = [System.IO.Path]::GetTempFileName() +lf -last-dir-path="$tmp" $args +if (test-path -pathtype leaf "$tmp") { + $dir = type "$tmp" + remove-item -force "$tmp" + if (test-path -pathtype container "$dir") { + if ("$dir" -ne "$pwd") { + cd "$dir" + } + } +}