自用
# @Author: zendu
# @Date: 2021-08-31 13:38:08
# @Last Modified by: zendu
# @Last Modified time: 2021-08-31 13:38:08
# @Usage: source ~/script.sh -bash
# @ echo 'alias sw="source ./.proxy-script.sh"' >> ~/.zshrc
# @Usage: sw -git || sw bash || sw yarn || sw -yarn
declare _BASH="bash"
declare _NPM="npm"
declare _YARN="yarn"
declare _GIT="git"
declare _ALL="all"
declare _ADDRESS="127.0.0.1:7776"
add_bash(){
export https_proxy=${_ADDRESS}
export http_proxy=${_ADDRESS}
env | grep -E 'http(s)?_proxy'
}
del_bash(){
export https_proxy=
export http_proxy=
env | grep -E 'http(s)?_proxy'
}
add_npm(){
npm config set proxy=http://${_ADDRESS}
npm config list | grep -E 'proxy'
}
del_npm(){
npm config delete proxy
npm config delete https-proxy
npm config list | grep -E 'proxy'
}
add_git(){
git config --global http.proxy http://${_ADDRESS}
git config --global https.proxy https://${_ADDRESS}
git config --list | grep -E 'http(s)?.proxy'
}
del_git(){
git config --global --unset http.proxy
git config --global --unset https.proxy
git config --list | grep -E 'http(s)?.proxy'
}
add_yarn(){
yarn config set proxy http://${_ADDRESS}
yarn config set https-proxy http://${_ADDRESS}
}
del_yarn(){
yarn config delete proxy
yarn config delete https-proxy
}
add_all(){
add_bash
add_git
add_npm
add_yarn
}
del_all(){
del_bash
del_git
del_npm
del_yarn
}
msg(){
echo -e "\033[32m================${1}==================\033[0m"
}
if [[ $1 == $_BASH ]];then
msg $_BASH;
add_bash
elif [[ $1 == -$_BASH ]];then
msg -$_BASH;
del_bash
elif [[ $1 == $_NPM ]];then
msg $_NPM;
add_npm
elif [[ $1 == -$_NPM ]];then
msg -$_NPM;
del_npm
elif [[ $1 == $_YARN ]];then
msg $_YARN;
add_yarn
elif [[ $1 == -$_YARN ]];then
msg -$_YARN;
del_yarn
elif [[ $1 == $_GIT ]];then
msg $_GIT;
add_git
elif [[ $1 == -$_GIT ]];then
msg -$_GIT;
del_git
elif [[ $1 == $_ALL ]];then
msg $_ALL;
add_all
elif [[ $1 == -$_ALL ]];then
msg -$_ALL;
del_all
else
msg "None Matched"
fi