Created
April 11, 2011 22:48
-
-
Save dolmen/914543 to your computer and use it in GitHub Desktop.
Switches environment between ActivePerl and StrawberryPerl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal | |
if "%1"=="" goto :ShowEnv | |
:SetEnv | |
if /I "%1"=="SB" set NewPerlDir=C:\strawberry\perl | |
if /I "%1"=="AS" set NewPerlDir=C:\Perl | |
if "%NewPerlDir%"=="" echo Error: invalid arg& endlocal & goto :EOF | |
if not exist %NewPerlDir%\nul. echo Error: "%NewPerlDir%" doesn't exist!& endlocal & goto :EOF | |
setlocal | |
:CleanPATH | |
call :#PathFinder PerlExe perl.exe PerlExe | |
if "%PerlExe%"=="" goto :EndCleanPATH | |
call :#DirName PerlBinDir "%PerlExe%" | |
call :#DirName PerlDir "%PerlBinDir%..\" | |
call :õPATHRemove "%PerlBinDir%" | |
call :õPATHRemove "%PerlDir%\site\bin\" | |
goto :CleanPATH | |
:EndCleanPATH | |
endlocal & set "PATH=%PATH%" | |
echo %1: %NewPerlDir% | |
set AddPath=%NewPerlDir%\bin | |
if exist "%NewPerlDir%\site\bin" set AddPath=%AddPath%;%NewPerlDir%\site\bin | |
endlocal & set "PATH=%AddPath%;%PATH%" & prompt [%1] $P$G | |
:ShowEnv | |
setlocal | |
call :#PathFinder PerlExe perl.exe PerlExe | |
if "%PerlExe%"=="" echo No Perl in PATH.& exit /B 1 | |
call :#DirName PerlBinDir "%PerlExe%" | |
call :#DirName PerlDir "%PerlBinDir%..\" | |
::call :#Chop PerlDir %PerlDir% | |
echo Perl: %PerlDir% | |
call :#FType PLOpen .pl | |
echo .pl: %PLOpen% | |
:: TODO Check that %PLOpen% matches %PerlExe% | |
endlocal | |
:: Show all PERL* environment variables | |
set PERL | |
set RELEASE_TESTING | |
set AUTOMATED_TESTING | |
goto :EOF | |
:õPathRemoveExe | |
setlocal | |
call :#PathFinder P "%~nx1" | |
if "%P%"=="" endlocal & goto :EOF | |
call :#DirName P "%P%" | |
if not "%P:~-2,1%"==":" set P=%P:~0,-1% | |
setlocal EnableDelayedExpansion | |
set "P=!PATH:%P%;=!" | |
endlocal & endlocal & set "PATH=%P%" | |
goto :EOF | |
:õPATHRemove | |
setlocal EnableDelayedExpansion | |
set P=%~dp1 | |
if not "%P:~-2,1%"==":" set P=%P:~0,-1% | |
set "PATH=%PATH%;" | |
:õPATHRemove.1 | |
::echo Remove %P% | |
set "PATH=!PATH:%P%;=!" | |
if not "!PATH:%P%;=!"=="!PATH!" goto :õPATHRemove.1 | |
endlocal & set "PATH=%PATH:~0,-1%" | |
goto :EOF | |
:õPATHShift | |
setlocal | |
set P=%~dp1 | |
if not exist %P%nul\. endlocal & goto :EOF | |
if not "%P:~-2,1%"==":" set P=%P:~0,-1% | |
endlocal & set "PATH=%P%;%PATH%" | |
:#PathFinder | |
set "%1=%~$PATH:2" | |
goto :EOF | |
:#Chop | |
if "%2"=="" set %1=& goto :EOF | |
setlocal | |
set D=%2 | |
set D=%D:~0,-1% | |
endlocal & set "%1=%D%" | |
goto :EOF | |
:#DirName | |
set %1=%~dp2 | |
goto :EOF | |
:#ParentDir | |
if "%2"=="" set %1=& goto :EOF | |
call :#DirName %1 "%~dp2..\" | |
goto :EOF | |
:#FType | |
setlocal | |
for /F "usebackq tokens=2 delims==" %%i in (`assoc %2`) do set F=%%i | |
for /F "usebackq tokens=2 delims==" %%i in (`ftype %F%`) do set F=%%i | |
endlocal & set "%1=%F%" | |
goto :EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment