From 0311e129ca84fb1eee5e454f3ec9f8229e3c9c07 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 22 Feb 2015 23:48:33 -0600 Subject: [PATCH] Handle quoted paths I was annoyed at having to use short paths all the time in my aliases. It wasn't until I found a command that actually refused to work with a shortpath (running iisexpress.exe) I was determined to find a solution. It appears that the reason the quoted paths weren't working was due to the ::validate alias stuff. The for command would stumble on a quoted path, arguing that /foo was unexpected... The additions on lines 7-8 wrap the input in quotes and then strip the inner quotes. This variable is used in the for loop (instead of %*) for validating the alias. So long as the alias is valid (contains no spaces) then the existing method of appending the new alias to the aliases file works just fine because it still uses %*. --- bin/alias.bat | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/alias.bat b/bin/alias.bat index 1dcfdc5..140a9b2 100644 --- a/bin/alias.bat +++ b/bin/alias.bat @@ -1,27 +1,31 @@ @echo off set ALIASES=%CMDER_ROOT%\config\aliases +setlocal +:: handle quotes within command definition, e.g. quoted long file names +set _x="%*" +set _x=%_x:"=% -if ["%*"] == [""] echo Use /? for help & echo. & goto :p_show +:: check command usage +if ["%_x%"] == [""] echo Use /? for help & echo. & goto :p_show if ["%1"] == ["/?"] goto:p_help if ["%1"] == ["/reload"] goto:p_reload :: /d flag for delete existing alias if ["%1"] == ["/d"] goto:p_del %* if ["%2"] == [""] echo Insufficient parameters. & goto:p_help -::validate alias -setlocal -for /f "delims== tokens=1" %%G in ("%*") do set _temp2=%%G - set _temp=%_temp2: =% +:: validate alias +for /f "delims== tokens=1" %%G in ("%_x%") do set alias=%%G +set _temp=%alias: =% -if not ["%_temp%"] == ["%_temp2%"] ( +if not ["%_temp%"] == ["%alias%"] ( echo Your alias name can not contain a space endlocal goto:eof ) :: replace already defined alias -findstr /b /v /i "%_temp%=" "%ALIASES%" >> "%ALIASES%.tmp" +findstr /b /v /i "%alias%=" "%ALIASES%" >> "%ALIASES%.tmp" echo %* >> "%ALIASES%.tmp" && type "%ALIASES%.tmp" > "%ALIASES%" & @del /f /q "%ALIASES%.tmp" doskey /macrofile="%ALIASES%" endlocal