Skip to content

Instantly share code, notes, and snippets.

@timothystone
Created November 23, 2017 00:39
Show Gist options
  • Save timothystone/6453449a56e126b6ad3344c4d43451b1 to your computer and use it in GitHub Desktop.
Save timothystone/6453449a56e126b6ad3344c4d43451b1 to your computer and use it in GitHub Desktop.
How I set my proxy in ZSH
#in ZSH, add to ~/.zprofile
set_http_proxy() {
if [ -e $HOME/.proxyrc ]; then
. $HOME/.proxyrc
fi
if [ -z $http_proxy ]; then
echo "No proxy config, environment found, connection attempt failed."
echo "Let's setup a config or update your password."
read 'eid?eID: '
read -s 'password?Password: '
http_proxy="http://${eid}:${password}@<your.proxy.net:port>/"
https_proxy="http://${eid}:${password}@<your.proxy.net:port>/"
echo "export http_proxy=$http_proxy" > $HOME/.proxyrc
echo "export HTTP_PROXY=$http_proxy" >> $HOME/.proxyrc
echo "export https_proxy=$https_proxy" >> $HOME/.proxyrc
echo "export HTTPS_PROXY=$https_proxy" >> $HOME/.proxyrc
. $HOME/.proxyrc
fi
}
kill_http_proxy() {
rm $HOME/.proxyrc
unset_http_proxy
}
unset_http_proxy() {
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
}
# set the proxy
set_http_proxy
@daxinc
Copy link

daxinc commented Sep 18, 2018

Good stuff!

In mine settings, I don't like to key in my EID every time. So I just hard code it. And on line #14, I refer to the variable defined in #13.

# in ZSH, add to ~/.zprofile

eid=abc123

set_http_proxy() {
  if [ -e $HOME/.proxyrc ]; then
    . $HOME/.proxyrc
  fi  

  if [ -z $http_proxy ]; then 
    echo "No proxy config, environment found, connection attempt failed."
    echo "Let's setup a config or update your password."
    read -s 'password?Password: '
    http_proxy="http://${eid}:${password}@<your.proxy.net:port>/"
    https_proxy=$http_proxy
    echo "export http_proxy=$http_proxy" > $HOME/.proxyrc
    echo "export HTTP_PROXY=$http_proxy" >> $HOME/.proxyrc
    echo "export https_proxy=$https_proxy" >> $HOME/.proxyrc
    echo "export HTTPS_PROXY=$https_proxy" >> $HOME/.proxyrc
    . $HOME/.proxyrc
  fi  
}

@txynidakis
Copy link

Thanks this was very useful!

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