Language Selection

English French German Italian Portuguese Spanish

Using Menus For Command Line Programs and Scripts

Filed under
Howtos

THE holidays are coming (Christmas approaching), so I've taken advantage of some spare time to menu-ise commands that I use frequently. Those commands aren't the mere opening of an application and they often require dealing with input and output (in the command line). So I've created menu.sh and used dialog to craft the following menu, e.g. for operations associated with Techrights. I invoke this menu with the click of one button (of the mouse).

Rianne has a similar menu for commands she often runs (which are long and would otherwise need pasting or typing in length). Her menu looks something like this:

Rianne's menu

Here's the code (bash file) that renders the menu above (it's really that simple!):


#!/bin/bash

HEIGHT=15
WIDTH=40
CHOICE_HEIGHT=4
BACKTITLE="Aloha, Rianne"
TITLE="Rianne @ Ted"
MENU="Choose one of the following options:"

OPTIONS=(1 "Start VPN"
         2 "REDACTED"
         3 "REDACTED"
	4 "REDACTED"
	5 "REDACTED"
	6 "REDACTED"
	7 "REDACTED"
)

CHOICE=$(dialog --clear \
                --backtitle "$BACKTITLE" \
                --title "$TITLE" \
                --menu "$MENU" \
                $HEIGHT $WIDTH $CHOICE_HEIGHT \
                "${OPTIONS[@]}" \
                2>&1 >/dev/tty)

clear
case $CHOICE in
        1)
            echo "You chose Option 1"
sh ~/vpn.sh ;;

        2)
            echo "You chose Option 2"
REDACTED COMMAND ;;
        3)
            echo "You chose Option 3"
REDACTED COMMAND ;;
        4)
            echo "You chose Option 4"
REDACTED COMMAND ;;
        5)
            echo "You chose Option 5"
REDACTED COMMAND ;;
        6)
            echo "You chose Option 6"
REDACTED COMMAND ;;
        7)
            echo "You chose Option 7"
REDACTED COMMAND ;;

esac

Hopefully this inspires other people out there to do the same. It takes a while to set up, but it's a big time saver over the long run.

More in Tux Machines

Decision Making With If Else and Case Statements in Bash Scripts

In this chapter of bash beginner series, you'll learn about using if-else, nested if else and case statements in bash scripts. Read more

Debian GNU/Linux 11 (Bullseye) Artwork Contest Is Now Open for Entries

This is the moment for aspiring artists and designers who want to display their work in front of millions of Debian users to submit their best artwork for the upcoming Debian GNU/Linux 11 (Bullseye) operating system series, due for release in mid-2021. Submissions are opened until November 1st, 2020, but your artwork needs to meet the following specifications. For example, you will have to create a wiki page for your artwork proposal at DebianArt/Themes, write down a few words about your idea, use an image format that can be later modified using free and open source software, and add a license that lets the Debian Project distribute your artwork within Debian GNU/Linux. Read more

GNOME 3.36.5 Desktop Update Released with Various Improvements and Bug Fixes

Coming about a month after the release of the GNOME 3.36.4 update, GNOME 3.36.5 is here as the latest stable bugfix release for the GNOME 3.36 desktop environment series. As expected, the new update is packed with updated core components and apps to keep GNOME 3.36’s stability and reliability at the higher standards. Highlights of the GNOME 3.36.5 update include Firefox Sync improvements for the Flatpak version of the Epiphany (GNOME Web) web browser, along with a fix for the way newly created tabs are ordered when closing new tabs, as well as a fix for a drag-and-drop crash in File Roller that occurred when cancelling the file overwrite process. Read more

Android Leftovers