Skip to content

There is no reason to not have a nice menu - just because you are using bash

License

Notifications You must be signed in to change notification settings

stefanp2021/bash-menu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here's an updated version of the README reflecting the improvements:


Bash Menu

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.

Bash Menu

Features

  • 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

Prerequisites

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.

Usage

Step 1. Download the Bash Menu scripts

Download bash-menu.sh and bash-draw.sh and place them in the same directory.

Step 2. Import Bash Menu into your script

Import bash-menu.sh:

source /path/to/bash-menu.sh

Step 3. Create handlers for each menu item

Create handler functions for each menu item:

actionA() { echo "Action A"; return 1; }
actionB() { echo "Action B"; return 1; }
actionExit() { echo "Exiting..."; return 0; }

Step 4. Setup menu items

Populate the menuItems and menuActions arrays:

menuItems=("1. Item 1" "2. Item 2" "Q. Exit ")
menuActions=(actionA actionB actionExit)

Step 5. Override menu configuration as needed

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"

Step 6. Display the Menu

Initialize and display the menu:

menuInit
menuLoop

The menuLoop function will continue until a menu item returns 0.

Versioning

We use SemVer for versioning. See the tags on this repository.

Authors

See the list of contributors.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Thanks to top-scripts blog post for inspiration.

About

There is no reason to not have a nice menu - just because you are using bash

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%