mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-06-30 14:20:23 +02:00
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>
This commit is contained in:
@ -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)()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user