I move between two network locations every day with my laptop, and came up with this script to automatically assign the http_proxy environment variable based on my current network location. Add this line in to your .bash_profile and new terminal windows will pick up the proxy automatically:

export http_proxy=`networksetup -getwebproxy Wi-Fi | awk '{ if(NR == 1) enabled=$2; else if(NR == 2) server=$2; else if(NR == 3) port=$2;} END {if(enabled == "Yes") print "http://" server ":" port}'`

Broken up:

  1. use the networksetup tool to grab the proxy information
  2. store the enabled state, server and port
  3. if the proxy is enabled, output a formatted string (http://SERVER:PORT) otherwise nothing