Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash/ZSH for changing git/npm/global proxy info based on current Wifi SSID on Mac
alias airport="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
CURRENT_WIFI_SSID=$(eval airport -I | grep '^[[:space:]]*SSID' | sed -e 's/^.*SSID: //g')
proxy() {
export addy='http://www-west.sony.com:80'
git config --global http.proxy $addy
git config --global https.proxy $addy
npm config set http-proxy $addy
npm config set https-proxy $addy
export HTTP_PROXY=$addy
export HTTPS_PROXY=$addy
export http_proxy=$HTTP_PROXY
echo 'Using proxy'
}
noproxy() {
export addy=''
git config --global --unset-all http.proxy
git config --global --unset-all https.proxy
npm config delete http-proxy
npm config delete https-proxy
export HTTP_PROXY=$addy
export HTTPS_PROXY=$addy
export http_proxy=$HTTP_PROXY
echo 'Not using proxy'
}
[[ $CURRENT_WIFI_SSID != 'SWing' ]] && noproxy > /dev/null
[[ $CURRENT_WIFI_SSID == 'SWing' ]] && proxy > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment