Two profiles for development tools (work and home)

I have a script as shown below and I need a solution.

Scenario :
I am using development tools such as Android Package Manager, nodeJS (npm), Homebrew, etc. Daily. I need to use it at home and at work, but at work I am behind a proxy server, so I had to configure a proxy server on every single tool, for example.

npm config set proxy http://proxy:10

But when I work at home, I don’t need it, because the proxy does not provide the fastest bandwidth in the world :) I would say it is rather slow, and I do not want to spend my time downloading packages 10 times slower.

Question :
Is there any solution for two different profiles? Or do I need to write a bash script to change the proxy settings every time I change my location (work / home)?

Please let me know if this is possible, or if you have experience with a familiar script.
Thank!

+4
source share
2 answers

In general, I got a bash solution, which I added below:

# 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."
}

For reference, there are many good blog posts / articles, for example. here , here and here .

+3
source

, , . , npm, SSH- . / , .

npm ssh-tunnel, /prod/etc, - github repo .

+2

All Articles