Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ dist/
build/
*.egg-info/
.coverage
.ruff_cache/
.DS_Store
Thumbs.db
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/whichproxy/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 10 additions & 2 deletions src/whichproxy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/whichproxy/clinic.py
Original file line number Diff line number Diff line change
@@ -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]:
Expand Down
7 changes: 6 additions & 1 deletion src/whichproxy/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/whichproxy/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
}


Expand Down
22 changes: 22 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down