Skip to content

Instantly share code, notes, and snippets.

@dhanifudin
Created February 27, 2015 07:13
Show Gist options
  • Save dhanifudin/a57e3c13b0508cfe029a to your computer and use it in GitHub Desktop.
Save dhanifudin/a57e3c13b0508cfe029a to your computer and use it in GitHub Desktop.
Easy way to configure proxy environment
proxy_server=proxy.your.heart
proxy_port=8080
proxy_user=subhi%40your.heart
proxy_password=your.heart
function proxy() {
case "$1" in
enable)
if [[ -f $HOME/.proxyrc ]]; then
. $HOME/.proxyrc
if [[ -n "$proxy_server" && -n "$proxy_port" ]]; then
if [[ -n "$proxy_user" && -n "$proxy_password" ]]; then
export http_proxy="http://$proxy_user:$proxy_password@$proxy_server:$proxy_port"
else
export http_proxy="http://$proxy_server:$proxy_port"
fi
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
echo "Proxy environment variable set."
else
echo "Proxy configuration error"
fi
else
echo "Proxy configuration not found!"
fi
;;
disable)
unset http_proxy;
unset https_proxy;
unset ftp_proxy;
echo "Proxy environment variable removed"
;;
*)
echo "Usage: $0 {enable|disable}"
esac
}
Defaults env_keep += "http_proxy https_proxy ftp_proxy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment