Add single-select target menu (arrow-key)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-22 00:15:23 +07:00
co-authored by Claude
parent f8ddfa48a4
commit 6fa2891d41
+50 -1
View File
@@ -51,6 +51,53 @@ print_banner() {
echo "" echo ""
} }
# -----------------------------
# Danh sách target fix cứng (alias từ ~/.ssh/config)
# -----------------------------
TARGETS=("local" "ta" "toc" "oc" "cse" "vrc" "aws" "tk" "od")
TARGET_CURSOR=0
TARGET=""
# Vẽ menu single-select
draw_target_menu() {
if [ "$1" = "redraw" ]; then
printf '\033[%dA' "$(( ${#TARGETS[@]} + 2 ))"
fi
echo " Chọn target (↑↓: di chuyển | Enter: chọn):"
echo ""
local i
for ((i = 0; i < ${#TARGETS[@]}; i++)); do
local prefix=" "
if [ "$i" -eq "$TARGET_CURSOR" ]; then
prefix="${C_TITLE}▸ ${C_RESET}"
fi
printf '\r\033[K%s%s\n' "$prefix" "${TARGETS[$i]}"
done
}
# Chạy menu, đặt biến toàn cục TARGET
select_target() {
draw_target_menu
while true; do
IFS= read -rsn1 key
case "$key" in
$'\x1b')
read -rsn2 seq
case "$seq" in
'[A') TARGET_CURSOR=$(( (TARGET_CURSOR - 1 + ${#TARGETS[@]}) % ${#TARGETS[@]} ));;
'[B') TARGET_CURSOR=$(( (TARGET_CURSOR + 1) % ${#TARGETS[@]} ));;
esac
;;
'') # Enter
echo ""
TARGET="${TARGETS[$TARGET_CURSOR]}"
return
;;
esac
draw_target_menu "redraw"
done
}
# ----------------------------- # -----------------------------
# Main (phân nhánh theo argv) # Main (phân nhánh theo argv)
# ----------------------------- # -----------------------------
@@ -62,7 +109,9 @@ main() {
fi fi
print_banner print_banner
echo "${C_TITLE}===== 🧹 Cleanup-server =====${C_RESET}" echo "${C_TITLE}===== 🧹 Cleanup-server =====${C_RESET}"
echo " (menu chọn target sẽ thêm ở Task 2)" echo ""
select_target
echo " Đã chọn target: ${C_TITLE}${TARGET}${C_RESET} (chạy sẽ thêm ở Task 3)"
} }
main "$@" main "$@"