A script that allows a user to use arrow keys to select an item from a list. Sometimes using select
can be a bit clunky because the user doesn't get any visual feedback about what they're selecting unless a confirmation message is displayed (which adds more overhead).
- Table style menu
- Added the possibility to display the menu in table style or list style with option
-t
(-t
means table style) - Added the possibility to show first row as header of the table with option
-sh
(-sh
means showHeader)
- Added the possibility to display the menu in table style or list style with option
- Added the possibility to insert options with | separator to create multi-column table (eg.
options=("First option|First info" "Second option|Second info")
) - Added
selectedChoiceIndex
to store index of the selected option - Added the possibility to type number to select an option
- Added the possibility to quit typing 'q'
- Improved handling of other keys different from arrow keys or numbers
- Improved handling of colored options
- Improved performance
Typical (you have the script locally)
source ./get-choice.sh
Remote (you want the functionality, but don't want to clone or copy anything)
source <(wget -qO- https://raw.githubusercontent.com/PuffoCyano/shell-menu-select/master/get-choice.sh)
# or
source <(curl -s https://raw.githubusercontent.com/PuffoCyano/shell-menu-select/master/get-choice.sh)
# or
source /dev/stdin <<< "$(curl -s "https://raw.githubusercontent.com/PuffoCyano/shell-menu-select/master/get-choice.sh")"
All flags and an example are demonstrated via the --help
command.
source ./get-choice.sh
getChoice -h
options=("First option"
"Second option"
"Third option"
"Fourth option \033[0;31m(new)\033[0m")
getChoice -q "Select an option:" -o options
echo -e "Option $selectedChoice with index $selectedChoiceIndex"
options=("First option"
"Second option"
"Third option"
"Fourth option \033[0;31m(new)\033[0m")
getChoice -q "Select an option:" -o options -t
echo -e "Option $selectedChoice with index $selectedChoiceIndex"
options=("First option|First info"
"Second option|Second info"
"Third option|Third info|Another info")
getChoice -q "Select an option:" -o options -t
echo -e "Option $selectedChoice with index $selectedChoiceIndex"
options=("Column 1|Column 2|Third column"
"Second option longer|Second info"
"Third option|Third info plus|Another info longer than others")
getChoice -q "Select an option:" -o options -t -sh
echo -e "Option $selectedChoice with index $selectedChoiceIndex"