Set-proxy-mac.sh

来自OSSmedia
  1. !/bin/bash
  1. Create proxy.sh

cat << 'EOF' | sudo tee /usr/local/bin/proxy.sh > /dev/null

  1. !/bin/bash

export ProIP="http://127.0.0.1:2080" export http_proxy="$ProIP" export https_proxy="$ProIP"

  1. Execute the command passed as arguments

"$@" EOF

  1. Make proxy.sh executable

sudo chmod +x /usr/local/bin/proxy.sh

  1. Add Zsh completion for proxy.sh

mkdir -p ~/.zsh/completion

cat << 'EOF' > ~/.zsh/completion/_proxy.sh

  1. compdef proxy.sh

_proxy_sh() {

 local -a args
 args=(
   '*:: :_normal'
 )
 _arguments -s -S $args

}

_proxy_sh "$@" EOF

  1. Ensure the completion directory is sourced in .zshrc

if ! grep -q "fpath+=~/.zsh/completion" ~/.zshrc; then

   echo "fpath+=(~/.zsh/completion)" >> ~/.zshrc
   echo "autoload -U compinit && compinit" >> ~/.zshrc

fi

echo "proxy.sh setup complete with Zsh completion."