shell-proxy.plugin.zsh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/bash
  2. # shellcheck disable=SC1090,SC2154
  3. proxy() {
  4. # deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead
  5. if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then
  6. echo >&2 "proxy: DEFAULT_PROXY is deprecated, use SHELLPROXY_URL instead"
  7. SHELLPROXY_URL="$DEFAULT_PROXY"
  8. unset DEFAULT_PROXY
  9. fi
  10. # deprecate CONFIG_PROXY, use SHELLPROXY_CONFIG instead
  11. if [[ -n "$CONFIG_PROXY" && -z "$SHELLPROXY_CONFIG" ]]; then
  12. echo >&2 "proxy: CONFIG_PROXY is deprecated, use SHELLPROXY_CONFIG instead"
  13. SHELLPROXY_CONFIG="$CONFIG_PROXY"
  14. unset CONFIG_PROXY
  15. fi
  16. # the proxy.py script is in the same directory as this function
  17. local proxy="${functions_source[$0]:A:h}/proxy.py"
  18. # capture the output of the proxy script and bail out if it fails
  19. local output
  20. output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" ||
  21. return $?
  22. # evaluate the output generated by the proxy script
  23. source <(echo "$output")
  24. }
  25. _proxy() {
  26. local -r commands=('enable' 'disable' 'status')
  27. compset -P '*,'
  28. compadd -S '' "${commands[@]}"
  29. }
  30. compdef _proxy proxy