From eca93abd53a9fa4f974e0de34e396d86c6fd5df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:30:19 +0800 Subject: [PATCH 01/11] chore: bump whichproxy to 0.4.1 --- src/whichproxy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From f8cbf8312e2ea0a731debd60f1d83d0466f6eae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:35:46 +0800 Subject: [PATCH 02/11] chore: ignore .ruff_cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From ce6bc2ada1007652f9ee8b67282766f563c4dc59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:35:48 +0800 Subject: [PATCH 03/11] build: bump 0.4.1 and add ruff config --- pyproject.toml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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" From 0171f22aad59b97189b6e021b6dc97b93e9c5fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:37:16 +0800 Subject: [PATCH 04/11] docs: changelog for 0.4.1 bash suggest script --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58eafc8..a95fe06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.4.1 — 2026-08-26 + +- `suggest -o fix.sh` writes a bash script instead of PowerShell +- Clipboard copy also tries `wl-copy` / `xsel` +- CI now runs ruff + ## 0.4.0 — 2026-08-18 - `whichproxy ports` 扫描本机常见代理口(Clash / CC Switch / v2rayN) From c2314bbed52eef0b893cd429b4003bbdffdc0679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:37:18 +0800 Subject: [PATCH 05/11] fix: clipboard copy tries wl-copy and xsel --- src/whichproxy/clipboard.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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, From 9dcf8da91b7a509ea2496fa9de8cca5aaf42e430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:37:22 +0800 Subject: [PATCH 06/11] fix: drop unused suggest_fix import from clinic --- src/whichproxy/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]: From ba63dcf98567a303e46eff558289dbd9730a5352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:38:16 +0800 Subject: [PATCH 07/11] feat: suggest_fix includes script_sh for bash --- src/whichproxy/env.py | 6 ++++++ 1 file changed, 6 insertions(+) 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" + ), } From 889883cf28ab0f2b15727ee9e91d9fb318306bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:39:15 +0800 Subject: [PATCH 08/11] fix: suggest -o .sh writes bash instead of PowerShell --- src/whichproxy/cli.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/whichproxy/cli.py b/src/whichproxy/cli.py index b0f1228..fe915cc 100644 --- a/src/whichproxy/cli.py +++ b/src/whichproxy/cli.py @@ -116,13 +116,20 @@ 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.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) From 1c0762847e4fd0e0a8e69d0860b997f6d7663cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:39:16 +0800 Subject: [PATCH 09/11] test: suggest -o fix.sh writes bash --- tests/test_cli.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 23aa711..b55d5e8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -108,6 +108,19 @@ 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_ports_json( From de9fd26eaa0103b14b04fcb33013b80183550875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:39:57 +0800 Subject: [PATCH 10/11] docs: document suggest -o fix.sh --- README.md | 2 ++ 1 file changed, 2 insertions(+) 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 From 2ca9bd4c79875474aabd58a8b0321a072317c30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 17:36:04 +0800 Subject: [PATCH 11/11] Create parent directories for suggest -o. --- CHANGELOG.md | 1 + src/whichproxy/cli.py | 1 + tests/test_cli.py | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a95fe06..ad53938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 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 diff --git a/src/whichproxy/cli.py b/src/whichproxy/cli.py index fe915cc..4fccc71 100644 --- a/src/whichproxy/cli.py +++ b/src/whichproxy/cli.py @@ -124,6 +124,7 @@ def _cmd_suggest( 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}") if suffix == ".ps1": diff --git a/tests/test_cli.py b/tests/test_cli.py index b55d5e8..3ef5973 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -123,6 +123,15 @@ def test_suggest_writes_shell_script(tmp_path: Any, monkeypatch: pytest.MonkeyPa 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( monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str],