Last active
May 22, 2018 10:25
-
-
Save jrnewell/ecc7fbb4adfe8b0d92f9 to your computer and use it in GitHub Desktop.
Set current directory to GOPATH on MS Windows cmd
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 | |
goto START | |
------------------------------------------------------- | |
go-path.bat | |
set the GOPATH to current directory | |
Created Sat May 3 20:00:00 2014 | |
------------------------------------------------------- | |
:START | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
@REM get current directory | |
set newGoPath=%CD%\lib | |
set defaultGoPath=E:\Coding\go\lib | |
if /i "%1"=="default" ( | |
echo Revert to default GOPATH !defaultGoPath! | |
set newGoPath=!defaultGoPath! | |
) | |
if /i "!newGoPath!"=="%GOPATH%" ( | |
echo GOPATH is already set to !newGoPath! | |
goto FINISHED | |
) | |
@REM remove old go path | |
if /i NOT "!defaultGoPath!"=="%GOPATH%" ( | |
echo Removing %GOPATH%\bin from PATH | |
@call rmpath %GOPATH%\bin >nul 2>nul | |
) | |
@REM add new go path to PATH | |
if /i NOT "!newGoPath!"=="!defaultGoPath!" ( | |
echo Adding !newGoPath!\bin to PATH | |
set newPath=!newGoPath!\bin;!PATH! | |
) else ( | |
set newPath=!PATH! | |
) | |
@REM set new go path | |
echo Setting GOPATH to !newGoPath! | |
@REM set new go bin path | |
echo Setting GOBIN to !newGoPath!\bin | |
ENDLOCAL & set PATH=%newPath% & set GOPATH=%newGoPath% & set GOBIN=%newGoPath%\bin | |
:FINISHED |
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 | |
goto START | |
------------------------------------------------------- | |
rmpath.bat | |
remove a path element from path | |
Created Tue Sep 15 21:33:54 2009 | |
------------------------------------------------------- | |
:START | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
@REM require one argument (the path element to remove) | |
if _%1==_ goto USAGE | |
@REM ~fs = remove quotes, full path, short names | |
set fqElement=%~fs1 | |
@REM convert path to a list of quote-delimited strings, separated by spaces | |
set fpath="%PATH:;=" "%" | |
@REM iterate through those path elements | |
for %%p in (%fpath%) do ( | |
@REM ~fs = remove quotes, full path, short names | |
set p2=%%~fsp | |
@REM is this element NOT the one we want to remove? | |
if /i NOT "!p2!"=="%fqElement%" ( | |
if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p) | |
) | |
) | |
set path=!tpath! | |
@call :LISTPATH | |
goto ALL_DONE | |
------------------------------------------------------- | |
-------------------------------------------- | |
:LISTPATH | |
echo. | |
set _path="%PATH:;=" "%" | |
for %%p in (%_path%) do if not "%%~p"=="" echo %%~p | |
echo. | |
goto :EOF | |
-------------------------------------------- | |
-------------------------------------------- | |
:USAGE | |
echo usage: rmpath ^<arg^> | |
echo removes a path element from the path. | |
goto ALL_DONE | |
-------------------------------------------- | |
:ALL_DONE | |
ENDLOCAL & set path=%tpath% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment