mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-10 09:49:12 +08:00
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 %*.
This commit is contained in:
parent
17b4525e60
commit
0311e129ca
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user