diff options
author | fengkx <liangkx8237@gmail.com> | 2021-12-13 18:26:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-13 11:26:05 +0100 |
commit | e96b8bd52366b526d7ebb22d947b54d286d6da61 (patch) | |
tree | 4eec5853a39aed00afdd4f208449fa805c2ee8e8 /plugins/shell-proxy/shell-proxy.plugin.zsh | |
parent | a1a63f4c7d3e765ffc4af93793d6d45287e80291 (diff) | |
download | zsh-e96b8bd52366b526d7ebb22d947b54d286d6da61.tar.gz zsh-e96b8bd52366b526d7ebb22d947b54d286d6da61.tar.bz2 zsh-e96b8bd52366b526d7ebb22d947b54d286d6da61.zip |
refactor(shell-proxy)!: rename env vars to `SHELLPROXY_*` and add usage message (#10456)
BREAKING CHANGE: the `DEFAULT_PROXY` setting has been renamed to `SHELLPROXY_URL`,
and `CONFIG_PROXY` has been renamed to `SHELLPROXY_CONFIG`. See the plugin README
for more information.
Co-authored-by: Marc Cornellà <hello@mcornella.com>
Diffstat (limited to 'plugins/shell-proxy/shell-proxy.plugin.zsh')
-rw-r--r-- | plugins/shell-proxy/shell-proxy.plugin.zsh | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/plugins/shell-proxy/shell-proxy.plugin.zsh b/plugins/shell-proxy/shell-proxy.plugin.zsh index 315ade665..9d45b5269 100644 --- a/plugins/shell-proxy/shell-proxy.plugin.zsh +++ b/plugins/shell-proxy/shell-proxy.plugin.zsh @@ -1,16 +1,37 @@ #!/usr/bin/bash -# shellcheck disable=SC1090 - -__PROXY__="${0:A:h}/proxy.py" +# shellcheck disable=SC1090,SC2154 proxy() { - source <(env "DEFAULT_PROXY=$DEFAULT_PROXY" "$__PROXY__" "$1") + # deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead + if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then + echo >&2 "proxy: DEFAULT_PROXY is deprecated, use SHELLPROXY_URL instead" + SHELLPROXY_URL="$DEFAULT_PROXY" + unset DEFAULT_PROXY + fi + + # deprecate CONFIG_PROXY, use SHELLPROXY_CONFIG instead + if [[ -n "$CONFIG_PROXY" && -z "$SHELLPROXY_CONFIG" ]]; then + echo >&2 "proxy: CONFIG_PROXY is deprecated, use SHELLPROXY_CONFIG instead" + SHELLPROXY_CONFIG="$CONFIG_PROXY" + unset CONFIG_PROXY + fi + + # the proxy.py script is in the same directory as this function + local proxy="${functions_source[$0]:A:h}/proxy.py" + + # capture the output of the proxy script and bail out if it fails + local output + output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" || + return $? + + # evaluate the output generated by the proxy script + source <(echo "$output") } _proxy() { - local -r commands=('enable' 'disable' 'status') - compset -P '*,' - compadd -S '' "${commands[@]}" + local -r commands=('enable' 'disable' 'status') + compset -P '*,' + compadd -S '' "${commands[@]}" } -compdef '_proxy' 'proxy' +compdef _proxy proxy |