【bash】ターミナル上でプロキシを通す

~/.bash_profile

proxy=hogehoge.ac.jp:8080
switch_trigger=hogehoge_ssid

function set_proxy() {
  export http_proxy=$proxy
  export HTTP_PROXY=$proxy
  export ftp_proxy=$proxy
  export FTP_PROXY=$proxy
  export all_proxy=$proxy
  export ALL_PROXY=$proxy
  export https_proxy=$proxy
  export HTTPS_PROXY=$proxy
}

function unset_proxy() {
  unset http_proxy
  unset HTTP_PROXY
  unset ftp_proxy
  unset FTP_PROXY
  unset all_proxy
  unset ALL_PROXY
  unset https_proxy
  unset HTTPS_PROXY
}

if [ "`networksetup -getairportnetwork  en0  | awk '{print $4}'`" = "$switch_trigger" ]; 
then
  echo "Switch to proxy"
  set_proxy
else
  echo "Switch to no_proxy"
  unset_proxy
fi