Last active
December 27, 2020 13:15
-
-
Save patrickwyler/83149c52a56078a455fca802fce5d717 to your computer and use it in GitHub Desktop.
Set proxy for bash session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Place this method in your .bashprofile and replace the proxy placeholders @<proxy>:<proxy-port> | |
| # Set proxy for current Bash session | |
| # ------------------------------------------------------------------- | |
| setProxyForBash() { | |
| echo -e --- set proxy for bash session --- | |
| read -p "Enter your Password: " -s password && echo -e " " | |
| read -r -p "Are you sure? [y/N] " response | |
| if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] | |
| then | |
| if (( $# != 1 )) # Is parameter #1 zero length | |
| then | |
| echo -e "Parameter Username is zero length!" # Or no parameter passed. | |
| return 1 | |
| else | |
| export http_proxy=http://$1:$password@<proxy>:<proxy-port> | |
| export https_proxy=http://$1:$password@<proxy>:<proxy-port> | |
| export no_proxy=localhost,127.0.0.0/8,*.local | |
| fi | |
| else | |
| echo -e "Exit..." # Or no parameter passed. | |
| fi | |
| echo -e --- Finish! --- | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment