我有一个像下面这样的场景,我需要一个解决方案。
场景 :
我每天都使用 Android Package Manager、nodeJS (npm)、Homebrew 等开发工具。我需要在家里和工作中使用它,但在工作中我使用代理,所以我必须在每个工具上设置代理,例如
npm config set proxy http://proxy:10
但是当我在家工作时,我不需要它,因为代理不提供世界上最快的带宽:) 我会说,它很慢,我不想浪费时间下载包慢了 10 倍。
问题 :
是否有任何解决方案可以在这些工具上使用两个不同的配置文件?或者我每次更改位置(工作/家庭)时都需要编写一个 bash 脚本来更改这些代理设置?
如果可能,或者您对熟悉的场景有一些经验,请告诉我。
谢谢!
最佳答案
总而言之,我最终得到了我在下面添加的 bash 解决方案:
# Proxy
alias proxyChecker='env | grep -i proxy'
function enableProxy() {
export http_proxy=http://my_proxy.com:port
export {https,ftp,rsync}_proxy=$http_proxy
export {HTTP,HTTPS,FTP,RSYNC}_PROXY=$http_proxy
echo -e "Proxy environment variable set."
npm config set proxy $http_proxy
npm config set https-proxy $http_proxy
echo -e "npm proxy set."
git config --global http.proxy $http_proxy
git config --global https.proxy $http_proxy
echo -e "git global proxy set."
}
function disableProxy() {
unset {http,https,ftp,rsync}_proxy
unset {HTTP,HTTPS,FTP,RSYNC}_PROXY
echo -e "Proxy environment variable removed."
npm config delete proxy
npm config delete https-proxy
echo -e "npm proxy removed."
git config --global --unset http.proxy
git config --global --unset https.proxy
echo -e "git global proxy removed."
}
作为引用,有很多很好的博客文章/文章,例如here 、 here 和 here 。
关于git - 两个开发工具简介(工作和家庭),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27137690/