From 5688a3f560685e940f3c7bda9b36fa2d9783529c Mon Sep 17 00:00:00 2001 From: libm Date: Mon, 9 Jun 2025 17:46:57 +0800 Subject: [PATCH] fix: optimize watch_proxy to fix #151 --- script/clashctl.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/script/clashctl.sh b/script/clashctl.sh index 2f140c0..3e4f57e 100644 --- a/script/clashctl.sh +++ b/script/clashctl.sh @@ -3,8 +3,12 @@ function clashon() { _get_proxy_port - sudo systemctl start "$BIN_KERNEL_NAME" && _okcat '已开启代理环境' || - _failcat '启动失败: 执行 "clashstatus" 查看日志' || return 1 + systemctl is-active "$BIN_KERNEL_NAME" >&/dev/null || { + sudo systemctl start "$BIN_KERNEL_NAME" >/dev/null || { + _failcat '启动失败: 执行 clashstatus 查看日志' + return 1 + } + } local auth=$(sudo "$BIN_YQ" '.authentication[0] // ""' "$CLASH_CONFIG_RUNTIME") [ -n "$auth" ] && auth=$auth@ @@ -23,10 +27,12 @@ function clashon() { export no_proxy=$no_proxy_addr export NO_PROXY=$no_proxy + + _okcat '已开启代理环境' } watch_proxy() { - systemctl is-active "$BIN_KERNEL_NAME" >&/dev/null && [ -z "$http_proxy" ] && { + [ -z "$http_proxy" ] && [[ $- == *i* ]] && { _is_root || _failcat '未检测到代理变量,可执行 clashon 开启代理环境' && clashon } }