#!/bin/bash # Lists cook/dishes/*guest-agents*.cfg and prompts the user to pick one. # Meant to be sourced (not executed) from repo root, after `cook && make all` # has regenerated dishes. Sets $selected_dish to the chosen dish's basename # (no extension) on success, or exits non-zero. mapfile -t dish_name < <(find "cook/dishes/" -maxdepth 1 -type f \( -name "*guest-agents*" \) -printf "%f\n" | sed 's/\.[^.]*$//') if [ ${#dish_name[@]} -eq 0 ]; then echo "No files found in cook/dishes/." exit 1 fi echo "Available dishes:" for i in "${!dish_name[@]}"; do echo "$((i + 1)). ${dish_name[$i]}" done read -r -p "Enter the number of the dish you want to select: " choice if ! [[ "$choice" =~ ^[0-9]+$ ]] || (( choice < 1 )) || (( choice > ${#dish_name[@]} )); then echo "Invalid choice. Please enter a number from 1 to ${#dish_name[@]}." exit 1 fi selected_dish="${dish_name[$((choice - 1))]}" echo "You selected: $selected_dish"