Skip to content

Instantly share code, notes, and snippets.

@patrickwyler
Last active December 27, 2020 13:15
Show Gist options
  • Select an option

  • Save patrickwyler/83149c52a56078a455fca802fce5d717 to your computer and use it in GitHub Desktop.

Select an option

Save patrickwyler/83149c52a56078a455fca802fce5d717 to your computer and use it in GitHub Desktop.
Set proxy for bash session
# 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