summaryrefslogtreecommitdiff
path: root/plugins/shell-proxy/proxy.py
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2021-12-18 17:46:06 -0600
committerTuowen Zhao <ztuowen@gmail.com>2021-12-18 17:46:06 -0600
commit1bc186dabe12b3d01b2257e82f3a104c48b8b3c7 (patch)
tree54576312318c406b6ce2a35423198fcc92c8bf71 /plugins/shell-proxy/proxy.py
parent2a977876c6e85847652f097cc128e4ed5bec147a (diff)
parent904f8685f75ff5dd3f544f8c6f2cabb8e5952e9a (diff)
downloadzsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.tar.gz
zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.tar.bz2
zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/shell-proxy/proxy.py')
-rwxr-xr-xplugins/shell-proxy/proxy.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/plugins/shell-proxy/proxy.py b/plugins/shell-proxy/proxy.py
index 97f4cf873..14f2944cc 100755
--- a/plugins/shell-proxy/proxy.py
+++ b/plugins/shell-proxy/proxy.py
@@ -5,16 +5,22 @@ from subprocess import check_output, list2cmdline
cwd = os.path.dirname(__file__)
ssh_agent = os.path.join(cwd, "ssh-agent.py")
-user_proxy = os.environ.get("CONFIG_PROXY", os.path.expandvars("$HOME/.config/proxy"))
+proxy_env = "SHELLPROXY_URL"
+proxy_config = os.environ.get("SHELLPROXY_CONFIG") or os.path.expandvars("$HOME/.config/proxy")
+usage="""shell-proxy: no proxy configuration found.
+
+Set `{env}` or create a config file at `{config}`
+See the plugin README for more information.""".format(env=proxy_env, config=proxy_config)
def get_http_proxy():
- default_proxy = os.environ.get("DEFAULT_PROXY")
+ default_proxy = os.environ.get(proxy_env)
if default_proxy:
return default_proxy
- if os.path.isfile(user_proxy):
- return check_output(user_proxy).decode("utf-8").strip()
- raise Exception("Not found, Proxy configuration")
+ if os.path.isfile(proxy_config):
+ return check_output(proxy_config).decode("utf-8").strip()
+ print(usage, file=sys.stderr)
+ sys.exit(1)
def make_proxies(url: str):
@@ -53,8 +59,7 @@ class CommandSet:
cmdline("echo", _)
def usage(self):
- cmdline("echo", "usage: proxy {enable,disable,status}")
- self.status()
+ print("usage: proxy {enable,disable,status}", file=sys.stderr)
def cmdline(*items):
@@ -65,7 +70,7 @@ def main():
command = CommandSet()
if len(sys.argv) == 1:
command.usage()
- sys.exit(-1)
+ sys.exit(1)
getattr(command, sys.argv[1], command.usage)()