本文使用AI整理
通过 alias
定义快捷命令,快速切换本地终端是否使用代理(适用于 Clash、Shadowrocket、V2Ray 等工具)。
在终端执行以下命令(任选其一):
vi ~/.zshrc
或
vi ~/.bash_profile
macOS 默认 shell 是
zsh
,所以推荐使用~/.zshrc
。
按 i
键进入插入模式,把下面的内容复制进去:
alias proxy="
export http_proxy=socks5://127.0.0.1:7890;
export https_proxy=socks5://127.0.0.1:7890;
export all_proxy=socks5://127.0.0.1:7890;
export HTTP_PROXY=socks5://127.0.0.1:7890;
export HTTPS_PROXY=socks5://127.0.0.1:7890;
export ALL_PROXY=socks5://127.0.0.1:7890;"
alias unproxy="
unset http_proxy;
unset https_proxy;
unset all_proxy;
unset HTTP_PROXY;
unset HTTPS_PROXY;
unset ALL_PROXY;"
按下 ESC
键,输入 :wq!
并回车,保存并退出编辑器。
在终端执行:
source ~/.zshrc
或
source ~/.bash_profile
proxy
unproxy
127.0.0.1:7890
是 Clash 等代理软件默认的 socks5
端口,可根据实际情况修改。curl: (7) Failed to connect
,请检查代理软件是否开启。~/.zshrc
后,都需要执行 source ~/.zshrc
让修改生效。命令 | 作用 |
---|---|
proxy |
开启代理 |
unproxy |
关闭代理 |
source ~/.zshrc |
让配置文件修改立即生效 |
— 2025年7月18日