shell-proxy.plugin.zsh
1411 bytes
1#!/usr/bin/bash
2# shellcheck disable=SC1090,SC2154
3
4# Handle $0 according to the standard:
5# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
60="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
70="${${(M)0:#/*}:-$PWD/$0}"
8
9eval '
10 proxy() {
11 # deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead
12 if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then
13 echo >&2 "proxy: DEFAULT_PROXY is deprecated, use SHELLPROXY_URL instead"
14 SHELLPROXY_URL="$DEFAULT_PROXY"
15 unset DEFAULT_PROXY
16 fi
17
18 # deprecate CONFIG_PROXY, use SHELLPROXY_CONFIG instead
19 if [[ -n "$CONFIG_PROXY" && -z "$SHELLPROXY_CONFIG" ]]; then
20 echo >&2 "proxy: CONFIG_PROXY is deprecated, use SHELLPROXY_CONFIG instead"
21 SHELLPROXY_CONFIG="$CONFIG_PROXY"
22 unset CONFIG_PROXY
23 fi
24
25 # the proxy.py script is in the same directory as this function
26 local proxy="'"${0:h}"'/proxy.py"
27
28 # capture the output of the proxy script and bail out if it fails
29 local output
30 output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_NO_PROXY="$SHELLPROXY_NO_PROXY" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" ||
31 return $?
32
33 # evaluate the output generated by the proxy script
34 source <(echo "$output")
35 }
36'
37
38_proxy() {
39 local -r commands=('enable' 'disable' 'status')
40 compset -P '*,'
41 compadd -S '' "${commands[@]}"
42}
43
44compdef _proxy proxy