Created
February 27, 2015 07:13
-
-
Save dhanifudin/a57e3c13b0508cfe029a to your computer and use it in GitHub Desktop.
Easy way to configure proxy environment
This file contains 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
proxy_server=proxy.your.heart | |
proxy_port=8080 | |
proxy_user=subhi%40your.heart | |
proxy_password=your.heart |
This file contains 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
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 | |
} |
This file contains 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
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