fix: read interactive input from /dev/tty for curl|bash runs

This commit is contained in:
FlintyLemming
2026-03-03 23:23:51 +08:00
parent 72fefab22d
commit 5cd803b90c
2 changed files with 30 additions and 4 deletions

View File

@@ -7,6 +7,19 @@ BLUE='\033[0;34m'; CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m'
_NAMES=(); _DESCS=(); _URLS=()
add() { _NAMES+=("$1"); _DESCS+=("$2"); _URLS+=("$3"); }
# Read from terminal even when script is run via `curl ... | bash`.
prompt_read() {
local __var_name="$1"
local __prompt="$2"
local __input=""
if [ -r /dev/tty ]; then
read -r -p "$__prompt" __input < /dev/tty
else
read -r -p "$__prompt" __input
fi
printf -v "$__var_name" '%s' "$__input"
}
# ════════════════════════════════════════════════════════════════════════════════
# CONFIGURATION — 在此处添加或修改脚本条目
# 用法: add "<显示名称>" "<脚本说明>" "<脚本 URL>"
@@ -67,7 +80,7 @@ main() {
while true; do
draw_menu
read -rp "请选择要执行的脚本 [0-$total]: " choice
prompt_read choice "请选择要执行的脚本 [0-$total]: "
if [[ "$choice" == "0" ]]; then
echo -e "\n${CYAN}[INFO]${NC} 已退出。\n"