Picker
- picker
- Arguments:
$1
… - List of choices to pick from- Output:
stdout - The choice that was selected
- Return Value:
The choice selected, between 1 and N
Bash CLI version of picker
Example
my_choice=$(picker Choice1 Choice2 ...)
- picker
- Arguments:
$1
- Variable name to store choice in$2
… - List of choices
- Parameters:
[DEFAULT_RESPONSE]
- Default choice [1…$#] (when user presses enter only)
- Output:
${!1}
- Stores text of choice selected${!1}_index
- Store the index in the array of the choice selected (starting at zero. So if 2 is selected, that’s index 1)TUI outputs to stderr.
Basic TUI for picking an option from a list of choices
Prints list of choices, and reads an answer until the user gives a valid response
Example
picker var "Choice one" "Choice II" "Choice 3"
#if 2 is selected
#var="Choice II"
#var_index=1
Bugs
If one of your choices has a newline in it, the value of ${!1}
will only contain the first line