Skip to content

Instantly share code, notes, and snippets.

@LeFreq
Last active January 28, 2020 02:09
Show Gist options
  • Save LeFreq/42e179487a47d1edc635e15fdedc6bcb to your computer and use it in GitHub Desktop.
Save LeFreq/42e179487a47d1edc635e15fdedc6bcb to your computer and use it in GitHub Desktop.
menu command for unix
Unix needs a menu command to standardize menu generation and make it easy to administer.
For the epic system, you need four core CLI functionalities to do everything: menu and user i/o processing (this file), text-file processing (line separation, field separation, words, etc.), OS interfacing (processes, users, files-on-disk, network, etc), and hardware interfacing/querying (bytes used, cpu %age, heat, .
Next, imagine the perfect name for every command or micro-app you build, so that that can be a clear ontology of commands on which to build further. Each name should be as potent as can be -- compact yet full of meaning. If you can't think of a good name, no one else will understand your command-line app either. It might mean that you already have the commands you need, built by others, or it may mean that you don't yet have the perfect idea of how to accomplish what you want. So, step back, and meditate on it a little. This is the secret for making apps simple and self-documenting, and together these mean re-useable.
First task: a menu shell-script. It takes a file as input. This input consists of the prior menu name (+ line feed), text menu selection items, a tab, and command-line that will be executed if that selection is chosen. Use tab-delimited fields for everything, and a enhanced "more" command that allows you to set the spaces between tabs when needed. The menu command will automatically display a letter for the choice if you've written the text lines with a caPital (chosing the first capital on the line), or a number and auto-capitalize the first word if you didn't. If the user, hits the "?" key, it will re-display the list with the command-lines used. If no filename is given, it will look and use a file called "home.ch". If there is a single-field line in the first line, it will offer a "back" command to go up a level in the menu structure.
Escape characters can delimit uppercase text that is not to be used as an letter-selection menu item. Also, the command can check just the first line for a capital to see if you're using that technique and automatically captialize the first, non-trivial, unique word on subsequent lines.
An automatic "Up" command? No. If the input file has a single-field line at the first line, assume that is the upwards choice file. If it has a blank line, assume that the menu should quit after a selection is made, otherwise re-enter the menu.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment