How to configure a proxy in a new network location using Terminal.app
Found this networksetup manual. To do this, you just need to write 

networksetup -setwebproxy "Service name (e.g. Wi-Fi)" proxy.server.com port