Skip to content

Instantly share code, notes, and snippets.

@lujiajing1126
Last active March 15, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lujiajing1126/7a1b171ab45761864eaf32be46fb243c to your computer and use it in GitHub Desktop.
Save lujiajing1126/7a1b171ab45761864eaf32be46fb243c to your computer and use it in GitHub Desktop.
let your command line program surf via proxy by adding one letter
#!/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
@lujiajing1126
Copy link
Author

update to support function

and also avoid function not found due to the lack of login shell profile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment