Skip to content

Instantly share code, notes, and snippets.

@BaksiLi
Last active May 21, 2022 11:06
Show Gist options
  • Save BaksiLi/fab184db1f5a466ea0108a6384cdab9f to your computer and use it in GitHub Desktop.
Save BaksiLi/fab184db1f5a466ea0108a6384cdab9f to your computer and use it in GitHub Desktop.
zsh function for proxy and undo proxy
function check_install {
output="$($1 --version)"
output_size=${#output}
if [ $output_size -eq 0 ]; then
echo '0'
else
echo '1'
fi
}
function proxy {
if (( $# == 0 )); then
export http_proxy=http://127.0.0.1:8234
export https_proxy=$http_proxy
export all_proxy=socks5://127.0.0.1:8235
echo "[+] HTTP Proxy on $http_proxy"
fi
case $1 in
git)
if [ $(check_install git) -ne 0 ]; then
git config --global https.proxy $proxy
git config --global http.proxy $proxy
echo "[+] Git proxied on $http_proxy"
fi
;;
npm)
if [ $(check_install npm) -ne 0 ]; then
npm config set proxy $proxy
npm config set https-proxy $proxy
echo "[+] NPM proxied on $http_proxy"
fi
;;
esac
}
function unproxy {
if (( $# == 0 )); then
unset http_proxy
unset https_proxy
echo "[+] HTTP Proxy off"
fi
case $1 in
git)
if [ $(check_install git) -ne 0 ]; then
git config --global --unset http.proxy
git config --global --unset https.proxy
echo "[+] Git proxy off"
fi
;;
npm)
if [ $(check_install npm) -ne 0 ]; then
npm config delete proxy
npm config delete https-proxy
echo "[+] NPM proxy off"
fi
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment