mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-30 02:44:42 +01:00
This commit addresses a problem where the nc command installed via homebrew was being used preferentially over the intended version due to its higher precedence in the $PATH environment variable. Adjustments have been made to ensure the script selects the correct nc executable, avoiding conflicts and ensuring consistent behavior across different setups.
41 lines
1.2 KiB
Python
Executable file
41 lines
1.2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from urllib.parse import urlparse
|
|
|
|
proxy = next(os.environ[_] for _ in ("HTTP_PROXY", "HTTPS_PROXY") if _ in os.environ)
|
|
|
|
parsed = urlparse(proxy)
|
|
|
|
proxy_protocols = {
|
|
"http": "connect",
|
|
"https": "connect",
|
|
"socks": "5",
|
|
"socks5": "5",
|
|
"socks4": "4",
|
|
"socks4a": "4",
|
|
}
|
|
|
|
if parsed.scheme not in proxy_protocols:
|
|
raise TypeError('unsupported proxy protocol: "{}"'.format(parsed.scheme))
|
|
|
|
def make_argv():
|
|
if sys.platform == 'darwin':
|
|
# 'nc' in $PATH may be installed by homebrew, if without path
|
|
yield "/usr/bin/nc"
|
|
else:
|
|
yield "nc"
|
|
if sys.platform in {'linux', 'cygwin', 'darwin'}:
|
|
# caveats: the built-in netcat of most linux distributions and cygwin support proxy type
|
|
# caveats: macOS built-in netcat command not supported proxy-type
|
|
yield "-X" # --proxy-type
|
|
# Supported protocols are 4 (SOCKS v4), 5 (SOCKS v5) and connect (HTTP proxy).
|
|
# Default SOCKS v5 is used.
|
|
yield proxy_protocols[parsed.scheme]
|
|
yield "-x" # --proxy
|
|
yield parsed.netloc # proxy-host:proxy-port
|
|
yield sys.argv[1] # host
|
|
yield sys.argv[2] # port
|
|
|
|
subprocess.call(make_argv())
|