-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.sh
49 lines (43 loc) · 1.19 KB
/
proxy.sh
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
# add these script fragments to your .bashrc or .zshrc or other shell profile
# whether npm exists
npm_exist=true
if ! command -v npm &> /dev/null
then
$npm_exist=false
fi
# proxy settings
function proxy_on() {
# check whether this system is wsl2
if uname -r |grep -iq "WSL2";
then
export winip=`ipconfig.exe| grep 'Wi-Fi' -A 1000| grep 'IPv4 Address' -m 1| cut -d":" -f 2|sed -e 's/\s*//g'`
fi
# clash port
address="http://$winip:7890"
export http_proxy=$address
export https_proxy=$address
# git
git config --global http.proxy $address
git config --global https.proxy $address
# npm
if [ "$npm_exist" = true ]; then
npm config set proxy $address
npm config set https-proxy $address
fi
echo -e "proxy address $address"
}
function proxy_off(){
unset http_proxy https_proxy
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxy
npm config delete https-proxy
# npm
if [ "$npm_exist" = true ]; then
npm config delete proxy
npm config delete https-proxy
fi
echo -e 'proxy unset!'
}
# open proxy_on defaulted
proxy_on() > nul