https://github.com/wallentx/bashmenu.sh
source <(curl -sL bashmenu.sh)
https://github.com/wallentx/bashmenu.sh
bash cli menu select
Last synced: 6 months ago
JSON representation
source <(curl -sL bashmenu.sh)
- Host: GitHub
- URL: https://github.com/wallentx/bashmenu.sh
- Owner: wallentx
- License: gpl-3.0
- Created: 2023-11-28T06:28:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-14T00:07:44.000Z (about 2 years ago)
- Last Synced: 2025-03-11T09:52:38.750Z (over 1 year ago)
- Topics: bash, cli, menu, select
- Language: Shell
- Homepage: https://bashmenu.sh
- Size: 19.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bashmenu.sh
```bash
source <(curl -sL bashmenu.sh)
```
## Description
`bashmenu.sh` is a script offering single and multi-selection menu functionalities in bash. It is designed to be sourced into other scripts, not executed directly.
The script provides two main functions: `singleselect` and `multiselect`, each requiring specific positional arguments:
- **Display Legend Flag** (string): `"true"` to display navigation instructions, any other value to hide them.
- **Result Variable Name** (string): The name of the variable where the result will be stored (as an array).
- **Options** (array): An array of strings representing the menu options.
- **Default Selection**:
- For `multiselect`: An array of booleans (`true`/`false`) indicating preselected options.
- For `singleselect`: An integer representing the index of the default selected option.
## Usage
### Navigation Controls
- `↓` (Down Arrow): Move cursor down
- `↑` (Up Arrow): Move cursor up
- `⎵` (Space): Toggle selection (for multiselect) / Make selection (for singleselect)
- `⏎` (Enter): Confirm selection
## Examples
```bash
# Source the script
source <(curl -sL bashmenu.sh)
# Define options
my_options=("Option 1" "Option 2" "Option 3")
# Using multiselect
preselection=("true" "false" "false")
multiselect "true" result my_options preselection
# Using singleselect
singleselect "true" result my_options 0 # 0 is the index of the default selected option
# Display the result
idx=0
for option in "${my_options[@]}"; do
echo -e "$option\t=> ${result[idx]}"
((idx++))
done
```
The multiselect function was based on multiselect.miu.io