-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo_env.bat
71 lines (62 loc) · 1.72 KB
/
go_env.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@echo off
@rem HKLM=HKEY_LOCAL_MACHINE
@rem HKCU=HKEY_CURRENT_USER
set CurDir=%~dp0
set CurDir=%CurDir:~0,-1%
set ProjDir=%CurDir%\example
echo ProjDir %ProjDir%
call :GoEnvSet "%CurDir%" "%ProjDir%" GOROOT GOPATH
call :GoEnvShow
call :GoCompileProj "%ProjDir%"
pause
goto :eof
:GoCompileProj
setlocal EnableDelayedExpansion
call :color_text 2f "+++++++++++++GoCompileProj+++++++++++++++"
set ProjDir=%~1
pushd %ProjDir%
go build main\hello.go
.\hello.exe
go run main\hello.go
popd
endlocal
goto :eof
:GoEnvShow
setlocal EnableDelayedExpansion
call :color_text 2f "+++++++++++++GoEnvShow+++++++++++++++"
echo GOROOT=%GOROOT%
echo GOPATH=%GOPATH%
go env
endlocal
goto :eof
:GoEnvSet
setlocal EnableDelayedExpansion
set go_root_dir=%~1
set go_path_dir=%~2
@rem assign without space
endlocal & set %~3=%go_root_dir%& set %~4=%go_path_dir%
goto :eof
:QuerySystemEnv
setlocal EnableDelayedExpansion
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
reg query "HKEY_CURRENT_USER\Environment"
endlocal
goto :eof
@rem YellowBackground 6f ef
@rem BlueBackground 9f bf 3f
@rem GreenBackground af 2f
@rem RedBackground 4f cf
@rem GreyBackground 7f 8f
@rem PurpleBackground 5f
:color_text
setlocal EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
endlocal
echo .
goto :eof