Automatically setting OS X proxy configuration in the shell

I’ll make it quick. It’d be nice to have the proxy settings from the OS X network preference pane reflected in an http_proxy variable when they’re needed- it’s useful if your laptop regularly finds itself in more than one location. Unfortunately most of the solutions google yields are complex exercises in technical masturbation, so here’s mine: 9 lines of code, no settings stored in a file somewhere in /etc, no symlinks, no messing around:

Save .proxy_export.rb in your home folder:

Then add this to the end of your .bash_profile

Job done. As Albert said, “Make everything as simple as possible, but not simpler.”