V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
TArysiyehua
V2EX  ›  宽带症候群

mac 如何自动设置问题?

  •  
  •   TArysiyehua · 49 天前 · 800 次点击
    这是一个创建于 49 天前的主题,其中的信息可能已经有所发展或是发生改变。

    mac 上我使用 ClashX 设置代理,并且设置的是全局模式。 但是 shell 需要我手动设置代理。

    当我退出 ClashX 的时候,每次都要我手动编辑 shell 的配置文件,打开 ClashX 也要,就很麻烦。 一不小心没设置对 shell 就不正常了。

    有什么办法让我的 shell 的代理自动跟着 ClashX 的设置吗?

    5 条回复    2024-03-09 15:22:41 +08:00
    KaliZ
        1
    KaliZ  
       49 天前 via iPhone
    换 clashX pro
    noahlias
        2
    noahlias  
       49 天前
    tun mode
    orangie
        3
    orangie  
       49 天前
    写个 shell 脚本,如果能连接代理端口就以为 clash 开了,就设置代理环境变量,否则清除环境变量,把这个脚本在 profile 里 source 一下。
    orangie
        4
    orangie  
       49 天前
    我自己用 GPT 写了一个,挺好用的

    #!/bin/bash

    # 目标代理服务器的地址
    PROXY_HOST="localhost"

    # 检测的代理端口
    PROXY_PORT=10808

    # 检测端口是否开放
    nc -z $PROXY_HOST $PROXY_PORT > /dev/null 2>&1

    # 根据 nc 命令的退出状态来决定是否设置环境变量
    if [ $? -eq 0 ]; then
    echo "Proxy port is open. Setting up proxy environment variables."
    export http_proxy="http://$PROXY_HOST:$PROXY_PORT"
    export https_proxy="http://$PROXY_HOST:$PROXY_PORT"
    else
    echo "Proxy port is closed. Clearing proxy environment variables."
    unset http_proxy
    unset https_proxy
    fi
    darcyC
        5
    darcyC  
       49 天前
    就像 1 楼和 2 楼说的那样,你需要使用 ClashX Pro 里的 Tun 模式(增强模式)
    注意一下,不要同时启动 系统代理 和 增强模式,你只需要开启增强模式。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2722 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 10:53 · PVG 18:53 · LAX 03:53 · JFK 06:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.