Here's an updated version of the README reflecting the improvements:
Bash Menu is a Bash script to easily add an interactive menu to your scripts. The menu allows navigation and selection of items using keyboard inputs.
- Clear screen display with interactive menu
- Up/Down arrow keys for navigation
- Esc key jumps to and selects the last menu item
- Case-insensitive first character selection
Ensure the script runs in a Bash shell:
# Ensure we are running under bash
if [ "$BASH_SOURCE" = "" ]; then
/bin/bash "$0"
exit 0
fi
The bash-menu.sh
script requires bash-draw.sh
to be in the same directory.
Download bash-menu.sh
and bash-draw.sh
and place them in the same directory.
Import bash-menu.sh
:
source /path/to/bash-menu.sh
Create handler functions for each menu item:
actionA() { echo "Action A"; return 1; }
actionB() { echo "Action B"; return 1; }
actionExit() { echo "Exiting..."; return 0; }
Populate the menuItems
and menuActions
arrays:
menuItems=("1. Item 1" "2. Item 2" "Q. Exit ")
menuActions=(actionA actionB actionExit)
Customize menu variables:
menuTop=2
menuLeft=15
menuWidth=42
menuMargin=4
menuColour=$DRAW_COL_WHITE
menuHighlight=$DRAW_COL_GREEN
menuTitle="Super Bash Menu System"
menuFooter="Enter=Select, Up/Down=Prev/Next Option"
Initialize and display the menu:
menuInit
menuLoop
The menuLoop
function will continue until a menu item returns 0
.
We use SemVer for versioning. See the tags on this repository.
- Kris Johnson - barbw1re
See the list of contributors.
This project is licensed under the MIT License - see the LICENSE file for details.
Thanks to top-scripts blog post for inspiration.