An interactive cross-platform select menu for BASH & ZSH with no dependencies.
Either source the script or install it directly into preferred /bin
directory.
For Debian based systems install into the ~/.local/bin/
(replace the link with current repo one):
curl https://raw.githubusercontent.com/hinell/options-select-bash/master/options.select.bash -o ~/.local/bin/options.select.bash && chmod +x ~/.local/bin/options.select.bash
Use the following script to automatically install the options.select
on request.
Once installed, you can follow steps described above.
declare scriptURL="https://raw.githubusercontent.com/hinell/options-select-bash/master/options.select.bash";
declare scriptInstallPath="$HOME/.local/bin/options.select.bash";
[[ -s "$scriptInstallPath" ]] && return 0; # already installed;
echo -e "\e[;38;2;255;200;0mThis script requires external options.select.\n"\
"You want to automatically install it? (y=continue, Enter=abort\e[0m)"\
read YESNO
[[ "$YESNO" == 'y' ]] || {
echo "Aborting... See for more info https://github.com/hinell/options-select-bash.git";
return -1;
};
curl $scriptURL -o "$scriptInstallPath";
chmod +x "$scriptInstallPath";
$ rm ~/.local/bin/options.select.bash
The following script imports options-select
and lists options so you can choose them. It also sets up a custom prompt. The output can be read from the respective variables. These variables aren't available if script is invoked from prompt.
# src/myscript.bash
. options-select.bash
# Input
options=(one two three);
prompt="Please, select choice! [%index]/[%total]";
# Selection
# Options var is passed without dollar sign
options.select options $prompt;
# The output
echo "INDEX => $?"
echo "INDEX => $SELECTED_IDX"
echo "SELECTED => $SELECTED" # <- Selected value
./options.select.bash --version # print version
./options.select.bash from foo bar baz # select 3 opts; the 'from" is a command
Key | Description |
---|---|
🠉 | Mover cursor up |
🠋 | Mover cursor down |
Enter | Select entry (SELECTED is set, see above), index is returned |
CTRL+C | Abort and return -1 |
Run ./examples.bash
file from the termian to see the script in action.
No guarantee, support or maintanance until paid.
Terminals:
- Bash - 5.1.4
- Zsh - 5.8
Operating systems:
- Ubuntu 21.04
- Kubuntu 21.04
It relies heavily on ANSI and Terminal Emulation Software escape codes. It was written over a course of 7 days and under huge load of coffee cups 🍵. You are welcome to tip me off you like.
- Huge respect goes to Alexander K. on StackOverflow who inspired this script.
- inquirer.js - Terminal user interface written in JS for NodeJS
- survey - Similar, but written in Go
man console_codes
man terminfo
A collection of common interactive command line user interfaces.
Copyright (C) 2021- [email protected]