Skip to content

Instantly share code, notes, and snippets.

@0gust1
Created July 24, 2018 12:56
Show Gist options
  • Save 0gust1/2fabb03a78139f2b2f9c05b897065803 to your computer and use it in GitHub Desktop.
Save 0gust1/2fabb03a78139f2b2f9c05b897065803 to your computer and use it in GitHub Desktop.
Working behind a corporate proxy - snippet to copy/paste in your shell rc file (or profile)
setProxy(){
export all_proxy=socks://url.to.proxy:80
export http_proxy=http://url.to.proxy:80
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export ALL_PROXY=$all_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
export FTP_PROXY=$http_proxy
export no_proxy="localhost, 127.0.0.1, .internal.domain"
export NO_PROXY=$no_proxy
}
unsetProxy(){
PROXY_ENV=( \
"http_proxy" "ftp_proxy" "https_proxy" "all_proxy" \
"HTTP_PROXY" "HTTPS_PROXY" "FTP_PROXY" "ALL_PROXY" \
"NO_PROXY"\
)
for envar in ${PROXY_ENV[@]}
do
unset $envar
done
}
setProxy #by default, set the proxy
@0gust1
Copy link
Author

0gust1 commented Jul 25, 2018

  • put this snippet at the end of your shell *.rc file or your profile.
  • by default the proxy is configured at the shell launch
  • if you need to deactivate the proxy (because you work from home, for example), just type unsetProxy in your shell.
  • this snippet should work on linux, windows and OSX

TIPS :

The location of this file (shell rc file) depends of your system (Win/*Nix) and your command line environment.

Windows :

With git bash / Cmder : C:\Users\YOUR_USER\.bashrc (create it, if it doesn't exist)

With babun (http://babun.github.io/) : C:\Users\YOUR_USER\.babun\cygwin\home\USERNAME\.babunrc

OSX/Linux :

~/.bashrc (or ~/.zshrc, etc. depending on your choice of shell)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment