Simple Menu

Yet another Character Based *NIX Menu System

simple_menu was developed over roughly a ten (10) year period and has been in use – in various forms – for the past twenty (20) years or so.  As such, it is mature software.  It has weaknesses – most particularly the support for debugging new scripts is putrid – but it is rock solid and runs on a wide variety of *NIX systems.

Documentation is contained in the tar file as a man(1) page.

Overview

Briefly, the idea is to have a program which manages tasks which are implemented using shell scripts.  This program – simple_menu – is responsible for managing the display presented to the user, the arrangement and titling of menu options, and the invocation of the shell scripts and managing their execution environment.

My experience is that by delegating all these tasks – and a few more – to a supervisory program, the shell scripts become

Implementation Overview

Everything is included in a single file – called a ‘menu definition file’ – which is divided into various sections:

Displayed text for menu titles, item selection descriptions, and various user prompts is constructed by concatenating static text and variable contents.  Prompt strings are evaluated and re-evaluated aggressively so that internal state information can be modified by user actions and displayed.

The menu files are written in a ‘menu definition language’ which is fairly easy to learn.  It is free form, rather than being line oriented and consists of semi-colon (;) terminated statements.  Here is a simple example:

global FOO = 'bar'

from-env BAR = 'ar-foo' export BAR;

global DEFAULT_DIR = '.' ;

title ‘Main Menu’

shell 'his invokes a shell'

%( /bin/shi %)

;

 

reset-global 'Change Default Directory'

 from-user DEFAULT_DIR 'New Default Directory'

;

 

do-menu SUBMENU

;

 

menu SUBMENU

title 'his is a submenu'

A: shell 's command'

%( cd $DIR

   ls

%)

parm DIR = '' 'Directory to List:' + DEFAULT_DIR

;

 

B: shell 'echo command'

%( echo $TEXT %)

parm TEXT = '<none>' 'Text to Echo'

;

See the man page for (much) more detail and more examples.

Distribution

simple_menu is written in fairly portable ANSI C.  The latest gzipped tar file can be found here