Welcome to ArrowKeys Menu, the game changer for user input selection inside your bash or zsh terminal
This module will allow you to generate an arrow keys interactive selector menu for the users within the terminal, preventing from errors or mistakes when prompting the end user for an input, capturing/returning whether the option value or the option index value, all up to you!
Highly customizable, to suit your own needs/styles, making life easier for the developer and better solutions for the audience.
To use it, just download it in your project by cloning the repo or just wget the menu.sh script, like this:
git clone https://github.com/portobanco51/ArrowKeysMenu.git
or
wget https://raw.githubusercontent.com/portobanco51/ArrowKeysMenu/main/menu.sh
Note
For usage when downloaded with wget
, just tail -30 menu.sh
Once downloaded, you're ready to source it in your script, declare the prompt and options array, and execute the MENU command alongside the prompt and array to get in return the value or the index value selected by the user.
Here's an example:
For the BASH Terminal
#!/bin/bash
# Source the script
source ./ArrowKeysMenu/menu.sh
# Declare prompt
MENUPROMPT="Choose an option from the menu below: "
# Declare options array
OPTIONS=('Kali Linux (Best)' 'FreeBSD' 'Ubuntu' 'Windows 11' 'MacOS' 'Other')
# Call the function and pass the arguments
MENU "${MENUPROMPT}" $OPTIONS # w/ quotes
# Extract the selected option
RESULT=${OPTIONS[$?]}
echo -e "\nYou selected: $RESULT"
For the ZSH Terminal
#!/bin/zsh
# Source the script
source ./ArrowKeysMenu/menu.sh
# Declare prompt
MENUPROMPT="Choose an option from the menu below: "
# Declare options array
OPTIONS=('Kali Linux (Best)' 'FreeBSD' 'Ubuntu' 'Windows 11' 'MacOS' 'Other')
# Call the function and pass the arguments
MENU $MENUPROMPT $OPTIONS # w/o quotes
# Extract the selected option
RESULT=${OPTIONS[$?]}
echo -e "\nYou selected: $RESULT"