Automate your macOS Terminal HTTP/HTTPS proxy setting with .zshrc

For obvious reasons, I use proxy quite often. And now that I am doing a bit more coding with AI, I am starting to automate these and sharing them here.

Just add this to your ~/.zshrc
Do a "nano ~/.zshrc"

export http_proxy=`scutil --proxy | awk '
  /HTTPEnable/ { enabled = $3; }
  /HTTPProxy/ { server = $3; }
  /HTTPPort/ { port = $3; }
  END { if (enabled == "1") { print "http://" server ":" port; } }'`
export HTTP_PROXY="${http_proxy}"

export https_proxy=`scutil --proxy | awk '
  /HTTPSEnable/ { enabled = $3; }
  /HTTPSProxy/ { server = $3; }
  /HTTPSPort/ { port = $3; }
  END { if (enabled == "1") { print "http://" server ":" port; } }'`
export HTTPS_PROXY="${https_proxy}"