From 22d27afed5b1f3a126b7247039a554250ee6546a Mon Sep 17 00:00:00 2001 From: Hugo-KTM Date: Sun, 27 Aug 2017 19:46:47 +0200 Subject: [PATCH] Fix Cmder not changing to CMDER_START (#1399) * Fix Cmder not changing to CMDER_START Fix to allow Cmder to change to different startup directory if already on the same drive as CMDER_START possibly relevant: HOME != USERPROFILE * make "Cmder Here" work in more cases integrated suggestion from comments (test for trailing backslash to prevent doubling of trailing backslash) integrated suggestions from #1456: switching ```cd /d``` over to ```pushd``` to get support for UNC-paths * replaced 'cd /d' with 'pushd' replaced two more instances of 'cd /d' with 'pushd' to support network paths. Also added double quotes to the use of '%USERPROFILE%' to prevent issues with spaces. I also noticed that 'pushd', in contrast to 'cd /d' does not require the trailing backslash for drive roots (on Win7). Therefore I removed the trailing backslash check. * Don't assume / is needed at end * Update init.bat --- vendor/init.bat | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index ef54dfe..d2e4689 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -149,9 +149,9 @@ call "%user-aliases%" :: manually extracting the archive rather than executing the 7z sfx if exist "%CMDER_ROOT%\vendor\git-for-windows\post-install.bat" ( call :verbose-output Running Git for Windows one time Post Install.... - cd /d "%CMDER_ROOT%\vendor\git-for-windows\" + pushd "%CMDER_ROOT%\vendor\git-for-windows\" "%CMDER_ROOT%\vendor\git-for-windows\git-bash.exe" --no-needs-console --hide --no-cd --command=post-install.bat - cd /d %USERPROFILE% + pushd "%USERPROFILE%" ) :: Set home path @@ -159,10 +159,15 @@ if not defined HOME set "HOME=%USERPROFILE%" :: This is either a env variable set by the user or the result of :: cmder.exe setting this variable due to a commandline argument or a "cmder here" +setlocal enabledelayedexpansion if defined CMDER_START ( - cd /d "%CMDER_START%" -) + if "%CMDER_START:~-1%" neq "\" ( + SET "CMDER_START=%CMDER_START%\" + ) + pushd "!CMDER_START!" +) +endlocal if exist "%CMDER_ROOT%\config\user-profile.cmd" ( REM Create this file and place your own command in there