diff --git a/.gitignore b/.gitignore index 95bb597..083df90 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ dist/ build/ *.egg-info/ .coverage +.ruff_cache/ .DS_Store Thumbs.db diff --git a/CHANGELOG.md b/CHANGELOG.md index 58eafc8..ad53938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.4.1 — 2026-08-26 + +- `suggest -o fix.sh` writes a bash script instead of PowerShell +- `suggest -o nested/fix.sh` creates missing parent directories +- Clipboard copy also tries `wl-copy` / `xsel` +- CI now runs ruff + ## 0.4.0 — 2026-08-18 - `whichproxy ports` 扫描本机常见代理口(Clash / CC Switch / v2rayN) diff --git a/README.md b/README.md index 1a57ab3..99fb3d7 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ whichproxy doctor --copy # 诊断并复制本窗口修复命令 whichproxy ports # 看 7897 / 15721 谁在听 whichproxy suggest -o fix.ps1 . .\fix.ps1 # 只改当前窗口 +whichproxy suggest -o fix.sh +source ./fix.sh # POSIX 当前窗口 ``` ## 20 seconds diff --git a/pyproject.toml b/pyproject.toml index 39ebcd9..66d1a60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "whichproxy" -version = "0.4.0" +version = "0.4.1" description = "See whether a host uses your proxy or slips through NO_PROXY — built for AI CLIs on Clash." readme = "README.md" license = { text = "MIT" } @@ -21,7 +21,15 @@ classifiers = [ dependencies = [] [project.optional-dependencies] -dev = ["pytest>=8.0"] +dev = ["pytest>=8.0", "ruff>=0.4"] + +[tool.ruff] +line-length = 100 +target-version = "py310" + +[tool.ruff.lint] +select = ["E", "F", "W"] +ignore = ["E501"] [project.scripts] whichproxy = "whichproxy.cli:main" diff --git a/src/whichproxy/__init__.py b/src/whichproxy/__init__.py index cafd580..ba28834 100644 --- a/src/whichproxy/__init__.py +++ b/src/whichproxy/__init__.py @@ -1,3 +1,3 @@ """whichproxy — see whether a host uses your proxy or slips through NO_PROXY.""" -__version__ = "0.4.0" +__version__ = "0.4.1" diff --git a/src/whichproxy/cli.py b/src/whichproxy/cli.py index b0f1228..4fccc71 100644 --- a/src/whichproxy/cli.py +++ b/src/whichproxy/cli.py @@ -116,13 +116,21 @@ def _cmd_suggest( report = doctor_report(env) payload = report.get("suggest") or suggest_fix(env) if out: - path_text = str(payload.get("script_ps1") or "") from pathlib import Path path = Path(out).expanduser() + suffix = path.suffix.lower() + if suffix in {".sh", ".bash"}: + path_text = str(payload.get("script_sh") or "") + else: + path_text = str(payload.get("script_ps1") or "") + path.parent.mkdir(parents=True, exist_ok=True) path.write_text(path_text, encoding="utf-8", newline="\n") print(f"wrote {path}") - print("本窗口执行:. .\\" + path.name if path.suffix.lower() == ".ps1" else f"source {path}") + if suffix == ".ps1": + print("本窗口执行:. .\\" + path.name) + else: + print(f"source {path}") return 0 if json_mode: _print_json(payload) diff --git a/src/whichproxy/clinic.py b/src/whichproxy/clinic.py index e0e9be2..a3605d6 100644 --- a/src/whichproxy/clinic.py +++ b/src/whichproxy/clinic.py @@ -1,6 +1,6 @@ from __future__ import annotations -from .env import SAFE_NO_PROXY, suggest_fix +from .env import SAFE_NO_PROXY def clinic_findings(report: dict) -> list[dict]: diff --git a/src/whichproxy/clipboard.py b/src/whichproxy/clipboard.py index 37479aa..56e4463 100644 --- a/src/whichproxy/clipboard.py +++ b/src/whichproxy/clipboard.py @@ -26,7 +26,12 @@ def copy_text(text: str) -> None: err = (completed.stderr or "Set-Clipboard failed").strip() raise OSError(err) return - for command in (["pbcopy"], ["xclip", "-selection", "clipboard"]): + for command in ( + ["pbcopy"], + ["wl-copy"], + ["xclip", "-selection", "clipboard"], + ["xsel", "--clipboard", "--input"], + ): try: completed = subprocess.run( command, diff --git a/src/whichproxy/env.py b/src/whichproxy/env.py index 0de5cc0..1309751 100644 --- a/src/whichproxy/env.py +++ b/src/whichproxy/env.py @@ -172,6 +172,12 @@ def suggest_fix( f'$env:ALL_PROXY = "{proxy_url}"\n' f'$env:NO_PROXY = "{SAFE_NO_PROXY}"\n' ), + "script_sh": ( + f"export HTTP_PROXY={proxy_url}\n" + f"export HTTPS_PROXY={proxy_url}\n" + f"export ALL_PROXY={proxy_url}\n" + f"export NO_PROXY={SAFE_NO_PROXY}\n" + ), } diff --git a/tests/test_cli.py b/tests/test_cli.py index 23aa711..3ef5973 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -108,6 +108,28 @@ def test_suggest_writes_script(tmp_path: Any, monkeypatch: pytest.MonkeyPatch) - text = out.read_text(encoding="utf-8") assert "NO_PROXY" in text assert "HTTPS_PROXY" in text + assert "$env:" in text + assert "export " not in text + + +def test_suggest_writes_shell_script(tmp_path: Any, monkeypatch: pytest.MonkeyPatch) -> None: + _set_clash_env(monkeypatch, no_proxy="localhost") + out = tmp_path / "fix.sh" + code = main(["suggest", "-o", str(out)]) + assert code == 0 + text = out.read_text(encoding="utf-8") + assert "export HTTPS_PROXY=" in text + assert "export NO_PROXY=" in text + assert "$env:" not in text + + +def test_suggest_creates_parent_dirs(tmp_path: Any, monkeypatch: pytest.MonkeyPatch) -> None: + _set_clash_env(monkeypatch, no_proxy="localhost") + out = tmp_path / "nested" / "dir" / "fix.sh" + code = main(["suggest", "-o", str(out)]) + assert code == 0 + assert out.is_file() + assert "export HTTPS_PROXY=" in out.read_text(encoding="utf-8") def test_ports_json(