Skip to content

Instantly share code, notes, and snippets.

@lujiajing1126
Last active March 15, 2017 17:03
Show Gist options
  • Select an option

  • Save lujiajing1126/7a1b171ab45761864eaf32be46fb243c to your computer and use it in GitHub Desktop.

Select an option

Save lujiajing1126/7a1b171ab45761864eaf32be46fb243c to your computer and use it in GitHub Desktop.

Revisions

  1. lujiajing1126 revised this gist Mar 15, 2017. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions use-proxy
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    #!/bin/bash
    # you can set alias p="use-proxy" in your .bashrc or .zshrc
    # then you can type: p curl https://google.com
    # also use with sudo: p -u echo 1
    set -e

    usage () {
    @@ -27,4 +26,8 @@ while getopts ":u" opt; do
    esac
    done

    exec "$@"
    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
  2. lujiajing1126 revised this gist Nov 26, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions use-proxy
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/bin/bash
    # you can set alias p="use-proxy" in your .bashrc or .zshrc
    # then you can type: p curl https://google.com
    # also use with sudo: p -u echo 1
    set -e

    usage () {
  3. lujiajing1126 revised this gist Nov 26, 2016. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions use-proxy
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,27 @@
    # 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

    exec "$@"
  4. lujiajing1126 created this gist Nov 25, 2016.
    10 changes: 10 additions & 0 deletions use-proxy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/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

    echo "will run $@"
    export https_proxy=127.0.0.1:1235
    export http_proxy=127.0.0.1:1235

    exec "$@"