Last active
March 15, 2017 17:03
-
-
Save lujiajing1126/7a1b171ab45761864eaf32be46fb243c to your computer and use it in GitHub Desktop.
let your command line program surf via proxy by adding one letter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# you can set alias p="use-proxy" in your .bashrc or .zshrc | |
# then you can type: p curl https://google.com | |
set -e | |
usage () { | |
echo "use-proxy [-u] <command>" | |
exit 127 | |
} | |
[ $# -eq 0 ] && usage | |
echo "will run $@" | |
export https_proxy=127.0.0.1:1235 | |
export http_proxy=127.0.0.1:1235 | |
while getopts ":u" opt; do | |
case $opt in | |
u) | |
shift | |
exec sudo "$@" | |
exit 1 | |
;; | |
\?) | |
usage | |
;; | |
esac | |
done | |
if [ -z $(which $1) ]; then | |
zsh -c "source ~/.zshrc; https_proxy=127.0.0.1:1235 http_proxy=127.0.0.1:1235 $1" | |
else | |
exec "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update to support function
and also avoid function not found due to the lack of login shell profile