yume, an easily-customized menu

I often repeat the same latex, dvips, dvilj, gcc, javac, or java commands over and over while working on documents or programs. It used to be that I would move the cursor into an xterm, press up-arrow or control-R to recall a command, press return, and watch the command run. But finally, exasperated with having to press two or three keys when one or none would do, I wrote a Tcl program called yume that provides a ``just for me'' menu of commands. After I type a command into a text field of the yume window, I can execute it whenever I want by clicking on a do: button, or if I've enabled yume's ``EE'' option, just by moving the mouse cursor across the do-group.

yume is a general-purpose menu program comprising 120 lines of Tcl code augmented by shell scripts for special-purpose menus. It can be tailored most easily for common applications via command line options. For custom applications one can modify the Tcl code or the shell scripts.

The rest of this note (1) provides a non-technical overview and bit of background about using yume; (2) tells how to obtain and install it; (3) mentions shell scripts that use yume to work on the latest latex, C, or java files in a directory; and (4) describes yume command-line options.

-- James Waldby

Overview

A typical yume window with two ``do-groups'' is shown in the Figure . Each do-group has a button labeled ``do:'', an editable command text field, and a check-button labeled ``EE''. When you start yume with n command-line parameters, the text of your parameters gets copied into n command text fields. (Without parameters, it creates one blank field.) After that you can modify the text in any field whenever you like, and can resize the yume window to make buttons bigger or smaller.

Executing commands by clicking do: button --- Whenever you click a do: button, yume does the command list in the corresponding command field.

Executing commands by moving cursor across do-group --- If you click the ``EE'' checkbox in a do-group and toggle it on, the do: button's background color will change from blue to red to show that Entry Execution is Enabled. Moving the mouse cursor into the do-group area will execute the command field. This is convenient when you execute the same command list frequently. Note, each time you click EE, yume toggles Entry Execution and switches the do-button's background color.

What happens to command output? --- Output from your commands is treated the same way as output from yume. For example, if you type yume or yume & in a window to start yume, that window is where command output will appear. Or, if in a Bourne shell you typed yume > yume-out 2>&1 & then command output (from your commands' stdout and stderr) would go to file yume-out, and you could follow it via tail -f yume-out.

``!'' tells yume to execute commands in an xterm --- If your command list begins with a bang (!) yume removes the bang and routes the command list into a shell in an xterm.

If your command list is malformed, you'll see not-perfectly-clear error messages. For example, messages like

... yume-1script: unexpected EOF while looking for `''

... yume-1script: eval: line 2: syntax error

will appear if you try echo 'It\'s time to check' instead of

echo It\'s time to check

In a case like this, if you test the command at a shell prompt the error will be as obvious as it's going to get and you can quickly resolve the problem!

Getting and installing yume

yume is written in the Tcl language, and uses widgets from the Tk toolkit. If you don't have Tcl/Tk installed on your system you can obtain its sources from, for example, ftp://ftp.smli.com/pub/tcl/. If you have a Linux system, it is straightforward to install Tcl and its hundreds of man-pages from various distribution CDs.

Source code mentioned in this note is available at http://www-osl.cs.uiuc.edu/ ~j-waldby/yume/yume-1.2. x, where x is any of tar, tgz, shar or src. You only need one of these packages; each of them contains all of the source files. The .src package is like a low-tech shar file. It can be taken apart with a text editor if you don't have tar or a Unix shell to process one of the other packages. The source files are README, yume, yume-1script, yume-2script, yume-shar-tar, and C- or latex-related shell scripts and examples with names of form la* and egyu-*. yume-shar-tar is the script that runs tar and shar to create the package files.

After you get a package of yume files, (1) unpack the files, (2) fix paths and program names in the files, and (3) move most of them into a bin directory listed in your PATH environment variable, such as /usr/local/bin or ~/bin.

Several of the files contain hard-coded paths. The path /bin/sh appears in all the shell-script files. The path /usr/bin/wish appears in the #! line of yume to invoke wish, the ``simple windowing shell'' that runs Tcl scripts. You might need to change that path, or to execute yume via wish yume instead of yume. Use which wish to locate wish. Dreams (yumes) of future yume s include an install makefile or configure file.

The javae, lala, laps, lac, lacc, latex-2dvi, latex-2err, latex-2ps scripts assume subsets of the following are builtins of sh, or on your path: basename, echo, egrep, eval, gcc, g++, dvilj, dvips, emacs, export, ghostview, head, java, javac, latex, lpr, lpq, ls -t, test, which, xdvi, xterm. A future release may provide path and program configuration for better portability of yume.

Latest Latex, CC, and Java scripts

This section describes shell scripts that set up yume menus to process the latest (most-recently changed) Latex, CC, or Java files. Optionally, each script can accept a filename to process instead of the latest file. The functions these scripts provide may change in future, to improve ease of use and usefulness.

The lala script locates the most-recently modified *tex file in the current working directory, or a specified file. It prepares a yume with xdvi / dvilj-oriented commands: (1) latex the tex file if it's newer than dvi file, or if forced by extra parameter; (2) xdvi the dvi file; (3) edit the tex file; (4) dvilj|lpr the dvi file.

Like lala, laps locates the most-recently modified *tex file in the current working directory, or a specified file. It prepares a yume with dvips-oriented commands: (1) latex and dvips the tex file if tex is newer than dvi, or dvi than ps, or forced; (2) lpr the ps file; (3) dvips the dvi file; (4) edit the tex file; (5) ghostview the ps file.

Both lala and laps use scripts ( latex-2dvi and latex-2ps) to check ``newer than'' conditions and to run latex invisibly unless an error occurs. The scripts beep and quit when latex finishes without error; but if a latex error occurs, they use script latex-2err to present latex error log messages in an xterm window. Also, the editor-command that lala and laps give you depends on shell variable \$EDITOR.

Using an extra parameter to latex-2dvi and latex-2ps -- eg, an x following the filename -- overrides their time checks, to allow use of master documents. Also, you can tailor the script files as you like so your own usual options come up in the menu entries.

The lacc script sets up a yume to compile, edit, and execute g++ programs. Again, it is simple to tailor the script to your own preferences in compilers, switches, and editors, and to add additional menu lines for programs such as gdb or make. lac is similar but assumes .c rather than .cc extensions and invokes gcc instead of g++.

The javae script sets up a yume to compile, edit, and execute Java programs. The present version includes two spare java command lines you may wish to remove. For example, if zippi.java is the most-recent java program in your working directory, the command javae will give you a yume with the five commands emacs zippi.java &, javac zippi.java, java zippi, java, and java.

yume Command Line Options

The simplest way to start yume with a custom command menu is by typing yume and giving it a list of commands as parameters. For example,
yume "ls -l" "ls -a" "date;df"
will create a 3-do-groups menu with ls -l in group 1, ls -a in group 2, and date;df in group 3. Figure illustrates the yume windows for this example and the next three.

\includegraphics[height=64mm]{4egs.eps} \caption{Four Example yume\/s}

You can tailor the appearance and function of a yume by using the command-line options shown in Figure . Note, in option names, only the first two letters after the dash are significant; for example, any of -lab, -label, -lamb would serve the same function as -la.

The Geometry option, -at xgeom, allows you to specify size and placement of the yume window via standard window-manager geometry parameters. The default value is "-10-70". This places the window near the lower-right screen corner and does not control the window size.

The Button option, -bu ... -button, turns on shell-command button mode. That is, subsequent entries are treated as shell commands selectable by button click. One or several buttons can appear as a group on a line. Each -button, -do, or -tcl use starts a new group. For example,
yume -bu "ls -l" "ls -a" "date;df"
creates a one-line menu with three buttons carrying the given commands. Note, button text on a menu cannot be edited.

The Do option, -do, says to treat the next parameters as Do-group shell commands. yume implicitly is in Do-group mode at the outset. If you override this implicit setting (with any of -button, -do, or -tcl) then yume suppresses the exit button that ordinarily appears by default. Menu users can edit the text of Do-group commands.

The Label option, -la ... -label followed by a name, lets you label a button with text other than the button's command. In the button example given earlier, buttons received default labels ls -l, ls -a, and date;df. In the following example, they are labeled Long, All, and Space as shown in Figure .
{ yume -la Long -bu "ls -l" -la All "ls -a" -la Space "date;df" }

The Tcl option, -tc or -tcl, is similar to -button except that the following commands should be valid Tcl commands. For example, if file Z contains
yume -tcl exit -la Remenu "exec \$0 &; exit" &
then executing Z gives the yume at lower left in Figure ; clicking Remenu starts a new Z and exits the current one. If you maintain a menu setup in a file that you occasionally modify, a formula like this may be useful.

Short Form & Option & Example
-at xgeom & Geometry & -at +10+10
-bu & Button & -button ls "date; df ."
-do & Do & -do ls "date; df ."
-la buttonname & Label & -label nomen
-tc & Tcl & -tcl "source myfi"

In summary: When option switches -tcl, -do, or -bu appear among parameters, they change the parameter mode to Tcl-button, do-group or shell-button handling. If one of these switches appears in the parameter list before a command first appears, yume suppresses the default exit button. Buttons hold fixed shell or Tcl commands. Button lines and do-groups may be intermingled. See scripts egyu-do, egyu-mix, and egyu-bu for further examples.