增加工具函数, 交互式更新

This commit is contained in:
Olia Lisa
2026-04-20 22:56:53 +08:00
parent a6d423a755
commit 9819aaba95
+15
View File
@@ -137,6 +137,7 @@ check_config_file(){
fi
}
# 重启docker容器
restart_docker() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../" # 脚本文件夹绝对路径
@@ -160,3 +161,17 @@ restart_docker() {
docker-compose -f $script_dir/../docker-compose.yml down
docker-compose -f $script_dir/../docker-compose.yml up -d
}
# 展示当前值并询问用户新输入的值
# 用法: ask_update "提示语" "当前值(当前配置文件的值)"
# 示例:
# new_port=$(ask_update "请输入新的端口号" "$(jq -r '.inbounds[0].port' $config_dir/config.json)")
ask_update() {
local prompt="$1" # 提示语
local current_value="$2"
local input
read -p "${prompt} [当前: ${current_value}]: " input
# 用户直接回车则保留当前值,否则使用新输入
echo "${input:-$current_value}"
}