fn: ask_choose
Purpose
Prompt the user for a choice and store the entered value in a named variable.
Behavior
- Optionally displays the accepted choices next to the prompt label.
- Validates the response against a compact choice list when supplied.
- Supports expanded ranges such as A-D through _ask_expand_choices.
- Can either keep asking or accept the invalid value after warning.
Options
--label TEXT— Prompt label shown to the user.--var NAME— Shell variable that receives the chosen value. Defaults to choice.--choices SPEC— Comma-separated choices or ranges, e.g. "A-D,Q".--displaychoices 0|1— Controls whether choices are appended to the label.--keepasking 0|1— Controls whether invalid choices are re-prompted. Defaults to 1.--labelwidth WIDTH— Visible width used to align the prompt label.--pad COUNT— Number of spaces inserted before the prompt label.--labelclr ANSI— ANSI sequence used for the label.--inputclr ANSI— ANSI sequence used for the input.--colorize MODE— Colorize mode passed to ask.
Outputs (globals)
Variable named by --var.
Returns
- 0 after storing the selected or accepted value.
Usage
# Choose one letter from a compact range, or Q to go back.
ask_choose --label "Select action" --choices "A-D,Q" --var action
# Keep the accepted value in a named variable; do not repeat invalid entries.
ask_choose --label "Proceed" --choices "Y,N,Q" \
--keepasking 0 --displaychoices 1 --var confirmation
