From a5e3cee1594e40f9696e9b5092de4f6a98f0c1b3 Mon Sep 17 00:00:00 2001 From: Marco Gallegos Date: Fri, 21 Nov 2025 07:31:27 -0600 Subject: [PATCH] feat: Add `read_menu_choice` function for interactive input and modify `main_menu` to use it, defaulting to option 'A' for non-interactive sessions. --- vanity_setup.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/vanity_setup.sh b/vanity_setup.sh index 7c7f876..fcab9e4 100644 --- a/vanity_setup.sh +++ b/vanity_setup.sh @@ -207,6 +207,29 @@ install_docker_stack() { portainer/portainer-ce:latest >/dev/null } +read_menu_choice() { + local prompt="$1" + local response="" + + printf "%s" "$prompt" + if [ -t 0 ]; then + if read -r response; then + printf "\n" + printf '%s\n' "$response" + return 0 + fi + elif [ -r /dev/tty ]; then + if read -r response < /dev/tty; then + printf "\n" + printf '%s\n' "$response" + return 0 + fi + fi + + printf "\n" + return 1 +} + main_menu() { echo "Selecciona una opción:" echo " A) Instalar TODO (recomendado)" @@ -214,7 +237,11 @@ main_menu() { echo " D) Instalar Docker + Portainer + Lazydocker" echo " Q) Salir" echo "" - read -r -p "Opción [A/C/D/Q]: " choice + local choice="" + if ! choice="$(read_menu_choice "Opción [A/C/D/Q]: ")"; then + echo "No se detecta una entrada interactiva; se seleccionará la opción 'A' por defecto." + choice="A" + fi echo "" case "${choice:-A}" in A|a)