-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle quoted paths #398
Handle quoted paths #398
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
@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 | ||
|
@@ -13,20 +18,18 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the %_x% is needed in the arguments check, the declaration must remain at the top of the file. |
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably no need to replace
%*
with%_x%
here because if["%_x%"] == [""]
then["%*"] == [""]
will be true as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason %_x% is used here instead of %* is because of the surrounding quotes. If you use
if ["%*"] == [""]
and try to run the following aliasalias runapi=runas /netonly /user:domain\user "c:\Program Files (x86)\IIS Express\iisexpress.exe /site :WebAppName /trace:i"
you will receive the error "Files was unexpected at this time", because the quotes surrounding %* get mismatched with the quotes around "c:\Program Files...".