wslip=$(hostname -I | awk '{print $3}')
port=1080
PROXY_HTTP="http://${hostip}:${port}"
set_proxy(){
export http_proxy="${PROXY_HTTP}"
export HTTP_PROXY="${PROXY_HTTP}"
export https_proxy="${PROXY_HTTP}"
export HTTPS_proxy="${PROXY_HTTP}"
}
unset_proxy(){
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
}
test_setting(){
echo "Host ip:" ${hostip}
# echo "WSL ip:" ${wslip}
echo "Current proxy:" $https_proxy
}
if [ "$1" = "set" ]
then
set_proxy
elif [ "$1" = "unset" ]
then
unset_proxy
elif [ "$1" = "test" ]
then
test_setting
else
echo "Unsupported arguments."
fi
配置git的代理才可以享受上网了:
// 添加代理
git config --global http.proxy "${http_proxy}"
git config --global https.proxy "${http_proxy}"
// 移除代理
git config --global --unset http.proxy
git config --global --unset https.proxy