V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
TArysiyehua

mac 如何自动设置问题?

  •  
  •   TArysiyehua · Mar 9, 2024 · 1974 views
    This topic created in 791 days ago, the information mentioned may be changed or developed.

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

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

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

    5 replies    2024-03-09 15:22:41 +08:00
    KaliZ
        1
    KaliZ  
       Mar 9, 2024 via iPhone
    换 clashX pro
    noahlias
        2
    noahlias  
       Mar 9, 2024
    tun mode
    orangie
        3
    orangie  
       Mar 9, 2024
    写个 shell 脚本,如果能连接代理端口就以为 clash 开了,就设置代理环境变量,否则清除环境变量,把这个脚本在 profile 里 source 一下。
    orangie
        4
    orangie  
       Mar 9, 2024
    我自己用 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  
       Mar 9, 2024
    就像 1 楼和 2 楼说的那样,你需要使用 ClashX Pro 里的 Tun 模式(增强模式)
    注意一下,不要同时启动 系统代理 和 增强模式,你只需要开启增强模式。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2504 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 00:30 · PVG 08:30 · LAX 17:30 · JFK 20:30
    ♥ Do have faith in what you're doing.