Bash Interactive TUI Menu with whiptail Prompt
Wrap a risky operational script in a guided whiptail/dialog menu — checklists, confirmations, input validation, and a non-interactive flag — so on-call engineers run it safely at 3am without memorizing flags.
- Target user
- Platform teams turning tribal runbook scripts into guided operator tools
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who turns scary copy-paste runbooks into guided, hard-to-misuse tools. Build an interactive terminal menu around an operational Bash script.
I will provide:
- The underlying actions the script performs (e.g. restart service, rotate key, drain node)
- Which actions are destructive or irreversible
- What inputs each action needs and how to validate them
- Whether the same script must also run unattended from cron/CI
Your job:
1. **Pick the toolkit** — default to `whiptail` (ships with most distros) with a graceful fallback to `dialog`; detect availability at startup and degrade to plain `read` prompts if neither exists. Never hard-fail because a TUI library is missing.
2. **Design the menu tree** — a top-level `--menu` of actions, `--checklist` for multi-select steps, `--yesno` confirmations gated before anything destructive, `--inputbox`/`--passwordbox` for parameters. Keep destructive items visually flagged and never the default-highlighted choice.
3. **Validate every input** — re-prompt on bad values, enforce allowed ranges/regex, and echo back a summary screen ("You are about to drain node X in cluster Y") that requires an explicit confirm before execution.
4. **Keep the engine non-interactive** — structure the code so the TUI only collects variables, then calls the same pure functions a `--non-interactive`/`--yes` flag would call directly. The cron path must never block on a prompt. Show both entry points sharing one implementation.
5. **Strict mode and cleanup** — run under `set -euo pipefail`, restore the terminal on exit with a `trap` (clear, show cursor), and capture whiptail exit codes correctly (Cancel/Esc must abort, not proceed).
6. **Audit trail** — log every chosen action, its parameters, the operator (`$USER`), and the outcome to a log file or syslog, so the friendly UI does not cost you traceability.
7. **Progress and results** — use `--gauge` for long steps where possible, and end on a results screen summarizing what succeeded and failed with next steps.
8. **Python alternative** — note when to graduate to `questionary`/`rich` or `Textual` instead of whiptail, and what you gain.
Output: (a) the full annotated script with menu, validation, and dual entry points, (b) the confirmation/summary screen, (c) the logging hooks, (d) a short note on testing TUI flows non-interactively.
Be opinionated: collect-then-execute, confirm before destruction, and always preserve a scriptable non-interactive path.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Bash Word-Splitting and Quoting Hardening Prompt
Audit and rewrite a Bash script to eliminate unquoted-expansion bugs, unsafe word splitting, and glob injection while preserving intended behavior
-
Bash Exit-Code and Pipefail Propagation Audit Prompt
Audit a Bash script for swallowed failures, missing pipefail, and broken exit-code propagation through pipes, subshells, and command substitution
-
Bash getopts Long-Options Parser Prompt
Build a robust Bash option parser that supports both short flags and GNU-style long options with validation and a generated usage block
-
Bash Sourceable Function Library Pattern Prompt
Refactor scattered Bash helpers into a safe, namespaced, sourceable library that can be reused across scripts without polluting the caller's environment
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.