mmBs mmBs - 2 months ago 6x
Git Question

Two profiles on development tools (work and home)

I have a scenario like below and I need a solution.


I use development tools like Android Package Manager, nodeJS (npm), Homebrew etc. on daily basis. I need to use it at home and at work, but at work I am behind a proxy, so I had to set up the proxy on every single tool, e.g.

npm config set proxy http://proxy:10

But when I work at home, I don't need it, because the proxy doesn't provide the fastest bandwidth in the world:) I'd say, it's pretty slow and I don't want to waste my time to download packages 10 times slower.


Is there any solution to have two different profiles on these tools? Or I need to write a bash script to change these proxy setting every time I change my location (work/home)?

Please let me know, if it's possible or if you had some experiences with a familiar scenario.



All in all, I ended up with a bash solution I added below:

# Proxy
alias proxyChecker='env | grep -i proxy'

function enableProxy() {
    export http_proxy=
    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
    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 a reference, there are plenty of good blog posts / articles, e.g. here, here and here.