-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.ps1
51 lines (47 loc) · 1.27 KB
/
proxy.ps1
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
$PROXY = '127.0.0.1:1080'
function git_proxy() {
$git_http_proxy = git config --global --get http.proxy
if ( $git_http_proxy -eq "http://$PROXY" ){
git config --global --unset http.proxy
git config --global --unset https.proxy
Write-Output 'unset git proxy'
} else {
git config --global http.proxy http://$PROXY
git config --global https.proxy http://$PROXY
Write-Output "set git proxy $PROXY"
}
}
function npm_proxy() {
$npm_http_proxy = npm config get proxy
if ( $npm_http_proxy -eq "http://$PROXY/" ) {
npm config delete proxy
npm config delete https_proxy
Write-Output "unset npm proxy"
} else{
npm config set proxy http://$PROXY
npm config set https_proxy http://$PROXY
Write-Output "set npm proxy $PROXY"
}
}
function set_proxy() {
if ( $Env:http_proxy -eq "http://$PROXY" ) {
$Env:http_proxy=''
$Env:https_proxy=''
Write-Output 'now proxy is off'
} else {
$Env:http_proxy="http://$PROXY"
$Env:https_proxy="http://$PROXY"
Write-Output "now proxy is on; $Env:http_proxy"
}
}
switch ($args[0]) {
git {
git_proxy
}
npm {
npm_proxy
}
default {
set_proxy
}
}