{"id":37711796,"url":"https://github.com/dongzhenye/setproxy","last_synced_at":"2026-01-16T13:19:58.935Z","repository":{"id":304226479,"uuid":"1016452113","full_name":"dongzhenye/setproxy","owner":"dongzhenye","description":"一键配置 macOS 终端代理，支持 Clash、V2Ray、Surge 等主流代理工具","archived":false,"fork":false,"pushed_at":"2025-11-20T13:13:21.000Z","size":60,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-20T13:15:27.672Z","etag":null,"topics":["cli","macos","proxy","proxy-cofiguration","terminal"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dongzhenye.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-09T03:28:23.000Z","updated_at":"2025-11-20T13:13:25.000Z","dependencies_parsed_at":"2025-07-11T20:22:04.600Z","dependency_job_id":"b69460dd-0dbc-4f03-bb03-85b1eaa57888","html_url":"https://github.com/dongzhenye/setproxy","commit_stats":null,"previous_names":["dongzhenye/setproxy"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/dongzhenye/setproxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongzhenye%2Fsetproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongzhenye%2Fsetproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongzhenye%2Fsetproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongzhenye%2Fsetproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dongzhenye","download_url":"https://codeload.github.com/dongzhenye/setproxy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongzhenye%2Fsetproxy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","macos","proxy","proxy-cofiguration","terminal"],"created_at":"2026-01-16T13:19:58.073Z","updated_at":"2026-01-16T13:19:58.928Z","avatar_url":"https://github.com/dongzhenye.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# setproxy - macOS 终端代理配置工具\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Platform](https://img.shields.io/badge/platform-macOS-blue.svg)](https://www.apple.com/macos/)\n[![Shell](https://img.shields.io/badge/shell-bash-green.svg)](https://www.gnu.org/software/bash/)\n\n一键解决 macOS 终端不走代理的问题，支持所有主流代理工具。\n\n## 🎯 支持的代理工具\n\n✅ **Clash** / **ClashX** / **Clash for Windows**  \n✅ **V2Ray** / **V2RayX** / **V2RayU**  \n✅ **Surge** / **Shadowsocks** / **ShadowsocksX**  \n✅ **Trojan** / **Quantumult X**  \n✅ 任何支持 HTTP/HTTPS/SOCKS5 代理的工具\n\n## 🚀 快速开始（默认直连更安全）\n\n- 核心问题：终端不会自动用系统代理；TUN 模式或直连时不应强制导出代理。\n- 默认行为：**off**（直连），只写入命令别名，不导出代理、不改工具。\n\n```bash\n# 1. 克隆项目\ngit clone https://github.com/dongzhenye/setproxy.git\ncd setproxy\n\n# 2. 按场景执行（setproxy.sh/on/off 持久化）\n# 直连或 TUN（系统代理关闭时推荐）\n./setproxy.sh off\n\n# 系统代理场景，按需为工具同步\n./setproxy.sh on --with git,npm,pip      # 示例：我自己的常用组合\n# 或全工具\n./setproxy.sh on --all\n\n# 如是非交互环境、安全起见请显式确认\n# ./setproxy.sh on --with git,npm --force\n\n# 重复执行 setproxy on/off 会直接覆盖标记区（无确认）；仅旧配置/非交互场景需 --force\n\n# 查看状态/测试（不改配置）\n./setproxy.sh status\n./setproxy.sh test\n\n# 首次执行后，如需当前 shell 立即可用别名，请：\nsource ~/.zshrc\n```\n\n## 📱 日常使用（持久化开关）\n\n```bash\n# 开启代理（持久化 + 同步当前会话）\nproxy-on --with git,npm,pip   # 等同于 setproxy on --with ...\n\n# 关闭代理（持久化 + 清理当前会话）\nproxy-off --all               # 仅在需要同步关闭工具时加 --with/--all\n\n# 检查代理状态（持久化优先，额外展示当前 env）\nproxy-status\n\n# 测试代理连接（按当前状态测试，不假定开启）\nproxy-test\n```\n\n### 验证配置\n```bash\n# 查看代理状态\nproxy-status\n\n# 测试代理连接\nproxy-test\n\n# 手动检查环境变量\necho $HTTP_PROXY\n```\n\n## 📁 项目结构\n\n```\nsetproxy/\n├── README.md              # 使用说明\n├── setproxy.sh            # 核心命令入口（on/off/status/test）\n├── setup-proxy.sh         # 兼容入口，转发到 setproxy.sh\n└── configs/               # 配置文件模板（安装后复制到 ~/.setproxy）\n    ├── zshrc-proxy        # 核心命令别名，调用 setproxy.sh\n    ├── gitconfig-proxy    # Git代理配置\n    ├── npmrc-proxy        # npm代理配置\n    ├── pip-proxy          # pip代理配置\n    ├── go-proxy           # Go代理配置\n    ├── docker-proxy       # Docker代理配置\n    └── cargo-proxy        # Cargo代理配置\n```\n\n## 🔧 配置详情\n\n- **默认端口**：127.0.0.1:7890，可用 `--port` 或环境变量 `SETPROXY_PORT` 覆盖。  \n- **支持工具**（可选同步）：git / npm / pip / go / docker / cargo（通过 `--with` 或 `--all`）。  \n- **兼容系统**：macOS (zsh终端)。\n\n### 自定义代理端口\n\n```bash\n# 临时覆盖\nSETPROXY_PORT=8080 ./setproxy.sh on --with git\n# 或直接指定\n./setproxy.sh on --port 8080 --with git,npm\n```\n\n## 🎯 场景速览\n\n- **系统代理已开**：`setproxy on --with git,npm,pip`（按需列工具）；若全部同步用 `--all`。  \n- **TUN/直连**：`setproxy off`（默认）；不改工具，避免强制走本地端口。  \n- **仅工具清理**：`setproxy off --with git,npm,pip`（核心 off，工具同步关）。\n\n## 🔧 故障排除\n\n### 1. 命令不生效\n```bash\nsource ~/.zshrc        # 重新加载别名与标记区\n./setproxy.sh status   # 看持久化状态与当前 env 是否一致\n```\n\n### 2. 代理无法连接\n```bash\n# 检查代理服务是否运行（替换为你的端口）\nlsof -i :7890\n\n# 如果使用自定义端口，检查环境变量/参数\necho $SETPROXY_PORT\n\n# 重新开关\nproxy-off\nproxy-on --with git\nproxy-test\n```\n\n## ❓ 常见问题 (FAQ)\n\n### Q: 为什么终端不走系统代理？\nA: macOS 终端不会自动读取系统代理，需要通过环境变量导出。setproxy 负责持久化导出/清除，并可按需同步工具配置。\n\n### Q: 如何选择命令？\nA: 系统代理开 → `setproxy on --with ...`；TUN/直连 → `setproxy off`；若仅关工具 → `setproxy off --with ...`。\n\n### Q: 支持哪些代理端口？\nA: 默认 7890，可用 `--port` 或 `SETPROXY_PORT` 覆盖。\n\n### Q: proxy-on 和 proxy_on 有什么区别？\nA: 行为一致，`proxy-on`/`proxy-off` 推荐；下划线仅为兼容别名。\n\n### Q: 如何确认代理是否生效？\nA: `proxy-status` 查看持久化 + env；`proxy-test` 测试出口 IP 与常见站点连通性。\n\n### Q: 可以同时使用多个代理工具吗？\nA: 可以，但同一时间只能有一个工具监听代理端口。确保只运行一个代理工具，或配置它们使用不同端口。\n\n### Q: 为什么 npm/pip 还是很慢？\nA: \n1. 确认代理已开启：`proxy-status`\n2. 检查代理工具是否正常运行\n3. 某些包可能需要额外配置镜像源\n\n### Q: 如何在新终端窗口自动开启代理？\nA: 编辑 `~/.zshrc`，找到 setproxy 配置部分，取消注释最后的自动代理行。\n\n## 💡 注意事项\n\n1. **代理端口**：默认使用7890端口（支持Clash、V2Ray等主流工具）。如需修改端口，请参考上方\"自定义代理端口\"部分\n2. **网络切换**：更换网络环境时重新执行 `proxy-on`\n3. **首次使用**：如果命令不生效，执行 `source ~/.zshrc` 重新加载\n\n## 🔧 支持的工具配置\n\n- 核心命令：proxy-on/off/status/test（持久化开关，等同于 `setproxy.sh`）。\n- 工具同步：通过 `--with` 列出需要同步的工具，或 `--all` 一键全选（git/npm/pip/go/docker/cargo）。无参数时仅切核心，不动工具。\n- 常用示例：`proxy-on --with git,npm,pip`。\n\n## 🧭 工具脚本约定\n\n- 统一日志：前缀 `[git]` / `[npm]` / ...，使用简短中文文案，默认无 emoji。\n- 幂等对称：on/off 配置对称，不重复插入；未安装的工具脚本会提示/跳过。\n- 安全写入：敏感文件写前备份（如 Docker/Cargo），失败时明确报错；支持 dry-run。\n- 可观测：on/off 后回显当前工具配置，便于确认是否生效。\n\n## 🗑️ 卸载\n\n如需完全卸载配置：\n\n```bash\n# 1. 从 ~/.zshrc 中删除 setproxy 标记区\npython3 - \u003c\u003c'PY'\nimport re, pathlib\npath = pathlib.Path.home()/\".zshrc\"\nif path.exists():\n    data = path.read_text()\n    pattern = re.compile(r'# BEGIN setproxy.*?# END setproxy\\n?', re.S)\n    path.write_text(re.sub(pattern,'',data))\nPY\n\n# 2. 删除 Git 代理配置（如有）\ngit config --global --unset http.proxy\ngit config --global --unset https.proxy\n\n# 3. 删除 npm 代理配置（如有）\nnpm config delete proxy\nnpm config delete https-proxy\n\n# 4. 删除 pip 配置文件（如已创建）\nrm -f ~/.pip/pip.conf\n\n# 5. 清理用户目录副本\nrm -rf ~/.setproxy\n```\n\n## 系统要求\n\n- macOS 10.15 或更高版本\n- zsh（macOS 默认 shell）\n- 基础命令行工具：curl、lsof、git（通过 Xcode Command Line Tools 安装）\n\n## 维护者\n\n- **作者**：Dong Zhenye\n- **联系**：通过 [GitHub Issues](https://github.com/dongzhenye/setproxy/issues) 联系\n\n## 贡献\n\n欢迎提交 Issue 和 Pull Request！\n\n## 许可证\n\n[MIT License](LICENSE) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongzhenye%2Fsetproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdongzhenye%2Fsetproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongzhenye%2Fsetproxy/lists"}