fix: read interactive input from /dev/tty for curl|bash runs
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user