This is an interim web page for yume3
The yume3 distribution provides an examples/ directory that contains a few dozen examples of yume usage. This web page lists most of those examples, via screen shots, brief explanations, and links to example sources and explanatory files.
If you create useful or exemplary yume scripts yourself, please feel free to contribute them for inclusion in the examples/ directory. Send email to yume at pat7.com. Subject must begin with the word yume.
The following links take you to the indicated sections within this document.
echo This is def at `date`
". Each time abc or def
executes, the output is appended to file t. File t can be displayed
(on the console where abc-def-ghi was started) via the "cat t to
stderr" button. Each time ghi executes, the output overwrites file
u. File u can be displayed via the "cat u to stderr" button.
date-of-file contains commands illustrating yume's meta-mode controls. A meta-mode control is a percent sign and a code character at the beginning of a command, by which yume's usual method of command invocation can be altered. As noted in yume(1), a command from a yume menu is executed by a shell via a forked copy of yume, unless the command begins with a percent sign and a meta-mode code character, in which case the invocation method depends on that code character.
For details, please see explanatory note and yume-meta(1) [text] or yume-meta(1) [pdf]
Other meta-mode examples include test-y-2, test-y-4, and xterms-w-sh.
example-starter2 and later example-starter versions provide examples of menus created on-the-fly from strings in environment variables.
example-starter3 uses button margins and quanta sizes in an attempt to make buttons of uniform size. Note that example-starter4, the next example, uses -bw options rather than margins and quanta, to generate buttons that are pleasingly more uniform.
Please see the explanatory note for comments on using echo and xargs for proper quoting treatment of dynamic menu strings.
Here are a few comments about elements of this script: The
-at 100x400+77+7switch tells yume to locate a 100x400-pixel window's top left corner at (77,7), which will be quite near the top of your display, not far from the left edge. The switch sequence
-bu -la 'Find filename' \ "V=\`xclip -o\`; echo \"Finding \$V in $D\"; find . | grep \$V"starts a button row with a button labeled "Find filename" that runs the double-quoted command shown. Note that two double-quote characters within the command are backslash-quoted so they apply when yume executes the command, rather than when yume starts. Likewise, the dollar sign (in the
\$V
instances) is
backslash-quoted to delay $V
evaluation.
The value of `xclip -o`
(that is,
left-quoted xclip -o
) is current clipboard contents
(ie, whatever text was most-recently selected). When yume processes
the whole command, the shell runs xclip -o
and assigns
the value to V. The echo
command displays the selected
text and the current-directory name. The find
command
finds all the filenames in and beneath the current directory and
pipes them to grep
, which selects those that contain
the selected text.
Note, additional examples using xclip
appear
in url-and-misc. (The
same examples appear individually in um4, um5, and um6.)
If you click the EE button at the left end of the top row, the
background of the EE and do:
buttons turns red, as
shown in the second screen shot. The red background means that
"entry execution" is turned on and that the compilation command in
the text-box will execute whenever the mouse cursor crosses
the do:
button, rather than only when you click
the do:
button. (Clicking the EE button toggles EE
state -- from on to off or from off to on.)
The echo
command before the gcc command types a blank
line, to tell the user the compile has begun; the echo
command after gcc produces a beep (since \a stands for bell) when
the compile finishes. Compile errors, if any, will be listed
between the blank line and the bell.
Before it makes a menu, lac tests the existence of
half-a-dozen variables that specify window title, compiler name,
compiler options, editor name, source file extension,
and make
setting. If these variables (YTITL, YGCC,
YOPTS, YEDIT, YEXT, and YMAKE) have not been set,
lac assigns them default values: lac, gcc, -O3
-Wall, $EDITOR, .c, and nil.
As just noted, when YEDIT isn't set, YEDIT defaults to $EDITOR. If in turn EDITOR isn't set, YEDIT then defaults to emacs. If you ordinarily use some other text editor, set EDITOR appropriately. For example, with vim and bash, put the first of the following lines in file ~/.bashrc; or, with vim and csh, put the second line in ~/.cshrc :
export EDITOR=vim setenv EDITOR vim
In addition to the YOPTS option settings (which are -O3
-Wall
by default) lac may add
a -lm
switch to the compilation command that it
generates. This switch (referred to as MATHLIB
in lac code) is set if grep finds
"<math.h>
" or any of certain math functions (sqrt,
exp, log, etc) within the .c source file. If you add math library
references to your code after invoking lac, you can
either run lac again, or type -lm
within the do:-item's text box. That is, in case
of special circumstances, you can manually edit any of the text
boxes as you like. But if you find yourself frequently having to do
manual edits, then either change lac or create a
script to change it. The next two paragraphs describe two possible
customizations of lac via a script. Both of these
scripts appear in yume's examples/
directory.
First, note that the lacc utility exports
YTITL=$0, YGCC="g++", YEXT=".cc", and YMAKE=make
. Then it
invokes lac. This creates a C++ compilation aid
instead of a C compilation aid. The created menu has an additional
do:
group with a make
command, as shown in
red in the lacc screen shot
below.
Secondly, the lacx utility exports YTITL=$0,
YEDIT=x2, YOPTS="-O3 -Wall -lX11 -lforms -lXpm", and
YMAKE=make
. Then it invokes lac. This
creates a C compilation aid suitable for
compiling yume and other xforms-based programs.
(Remove or edit the YEDIT=x2
line unless x2 is an alias
for your text editor.)
lacc
", start
it with "lacc xyz
" or with "lacc xyz.cc
".
To locate the most-recently-modified .cc file, lacc uses shell code like
FILE=`ls -t *.cc | head -1`(Note, other scripts like lac and lala use similar shell code, but with ".c" or ".tex' rather than ".cc".)
The ls -t *.cc
portion of this code makes a list of
current-directory filenames that end with .cc, sorted by modification
time; the head -1
portion selects the first element from
that list. If the current directory has no filenames that end with
.cc, error messages like
ls: cannot access *.cc: No such file or directory egrep: .cc.cc: No such file or directorywill appear, and the resulting menu will refer to "filenames" like .cc and .cc.cc.
Also see discussion of lac.
Clicking the EE button at the left end of the top row toggles the
background of the EE and do:
buttons from blue to red
(or vice versa) as shown in the second screen shot. The red
background means that "entry execution" is turned on and that the
command in the text-box will execute whenever the mouse cursor
crosses the do:
button.
If you are using xdvi
to view your latex
output, and have entry execution turned on for
the latex-2ps
command, you can make and save a change to
your .tex file, then move the mouse cursor across the
red do:
button, and after you hear a beep [indicating
that latex
and dvi2ps
(and font generation,
if needed) are done], move the mouse cursor into
the xdvi
window. xdvi
will detect that the
.dvi file it is displaying has changed, and will display the new form
of your document.
Note, the latex-2ps
script uses latex
to
process a .tex file. latex-2ps runs latex invisibly unless an error
occurs. It beeps when done if latex
finishes without
error; but if a latex
error occurs, it uses script
latex-2err
to present selected latex error log messages
in an xterm window. In other words, if latex
and dvi2ps
processing goes ok, latex-2ps
beeps and is done; but if that processing has errors,
latex-2ps
invokes the latex-2err
script to
display some of the logged error messages in an xterm.
latex-2err
uses grep to suppress some latex
error messages. For example, it squeezes out messages containing "No
pages" and "Overfull", among others.
latex-2ps latex
's the specified tex file if it's
newer than its dvi file, or if an extra parameter is given after the
file name. The "x" at the end of each latex-2ps
command
just before the blue-line text-cursor mark in each screen shot is
just such an extra parameter, used to force latex
and dvi2ps
processing regardless of file dates. You may
remove the x if you wish.
The button pictured above was created on qili, and when it is clicked it opens an xterm that runs on qili and is displayed on the current display.
Note, menu-at-var
is mostly just a simple example of
placing a menu at different locations for different cases, rather
than a useful menu. In practice, one would use a slightly
longer xterm
command, for example like:
yume -bu -la yuli "xterm -e ssh yuli&" &which when run on qili would open a yuli xterm and display it on the current display.
do:
button (with the command as shown) a
sound will be played after a delay of 3 seconds.
Further discussion of play-sound-delay appears in its code file. But very briefly, the script structure is like:
[ -z $1 ] && { <yume command> exit; } <command to sleep $1 seconds, then play sound via play-sound-delay>The
[ -z $1 ] && { ... }
sequence says to test if
parameter 1 has zero length, ie, is missing. If it's missing,
the yume
command gets executed -- creating a menu that
contains recursive calls to play-sound-delay, as
shown above -- and the script exits. But if parameter 1 is present,
it is treated as a number of seconds to sleep, after which a sound is
played.
Note, some useful adaptions can be made simply by supplying
parameters to the screen-save invocation. See
comments near the beginning of its code.
For example, the pictures for this web page have titles
like eg-ss-10.jpg, eg-ss-11.jpg,
and so forth. These
pictures were saved using a screen-save menu that
was started by the command, "screen-save . eg-ss- 1
",
which saves pictures in current directory, gives them a prefix of
"eg-ss-", and numbers them with an interval of 1.
Note, the screen-save menu uses the screen-save script recursively to do different imports, supplying a fourth parameter to control what the script does. For a simpler example and brief explanation of this technique, please see the closing paragraphs of the discussion of play-sound-delay.
Commands for the Subversion version control system typically have
the form "svn V F
" where V is a verb and F is a filelist.
Examples: "svn log myfile.c
" and "svn cat
myfile.c
"
Several commands have the form "svn V
"; for example,
"svn status
" and "svn update
".
To tell the menu where your svn-versioned files are located, type the directory name into the "Directory D:" textbox. (This will set environment variable D within yume's environment.) The path you type into the textbox should be relative to the path shown on the line above it. (The screen-shot path has been blurred out.)
To tell the menu the filelist that commands should apply to, type the filenames into the "File list F:" textbox.
To execute an svn command with the verb add, proplist, status, update, info, log, diff, cat, list, or commit, click the correspondingly-named button. Then svn will apply the verb to your specified filelist.
As you can see in the
svn-buttons code, the "Props-id $F
"
button will run the command sequence
cd $D; svn propset svn:keywords "Date Id" $Fwhich will tell svn to enable expansion of $Date$ and $Id$ sequences within the specified files.
The "ls -l $F
" button will run the command sequence
cd $D; ls -l $Fwhich will show directory details of the files in the filelist.
The Subversion system comes with help files that can be accessed by
commands of the form "svn help V
", where V is an svn
verb or an svn help topic. To display help text on the console
where you ran svn-buttons, put the topic name in
the "Help Topic:" textbox and click the "Help Topic:" button.
See explanatory note for further
comments, if you don't want EDIT=emacs
when an svn commit
is done. (EDIT controls the editor that svn invokes for the user to
record comments upon commit.)
Note, however, sequences like "-la 'Bye-bye' -ex
" to
apply a label other than "exit" to an exit button.
Note, the menu goes away if either button is used.
Other meta-mode examples include date-of-file, test-y-4, and xterms-w-sh.
In like manner, one can create xterms set up for particular purposes.
The other textboxes create equivalent xterms, aside from not showing or setting M. The command beginning with %: is executed by invoking /usr/bin/xterm (within a forked copy of yume) directly rather than invoking /bin/sh (within a forked copy of yume) to invoke xterm. The command beginning with %- invokes /usr/bin/xterm directly from yume, without forking. Hence the yume menu disappears when the xterm opens in response to that command.
Other meta-mode examples include date-of-file, test-y-2, and xterms-w-sh.
-de gtkrc
option switch to select a particular
gtkrc file, and in that file, setting the colors that will be used for
buttons in a yume menu. The commands within this menu are not
particularly useful or interesting, but merely serve to populate a
menu so that button colors can be observed.
A particular gtkrc file is selected by a yume option of the
following form: -de gtkrc:nameoffile
. For example,
test-y-5 says:
yume ... -de gtkrc:./yume3-gtkrc-5A ...
Note, if your home directory contains file
.yume3-gtkrc
, settings from that file normally are processed
by gtk_init() before settings from a -de specified gtkrc file are
processed. You can suppress processing of
~/.yume3-gtkrc
via: -de nogtkrc
. The nogtkrc
flag does not suppress files mentioned by -de gtkrc:
,
however.
In the gtkrc file, foreground and background colors can be specified for various widgets in various states. For example, the EE buttons' normal font color and background color in this example are given by:
style "y3ee" = "y3m" { fg[NORMAL] = "blue" bg[NORMAL] = "YellowGreen" }Style y3m, found at the beginning of yume3-gtkrc-5A, defines a base-level color scheme for yume3 buttons. Styles for specific buttons can override whatever the user wants to be different from the base-level scheme, in this case normal-status text color and button background color.
In this example, the topmost EE button has been clicked. Thus, that EE button is in Active state (for which, bg[ACTIVE] is "tan", from y3m style), rather than Normal. When an EE button is Active, its associated do: button is named "y3dr" (for which, bg[NORMAL] is "red2") rather than "y3dp" (for which, bg[NORMAL] is "blue", from y3m style). When the screenshot was taken, the mouse was over the large 'Bye-bye' button, which is sky-blue because y3m specified bg[PRELIGHT]="SkyBlue".
Note, the top three rows in this menu are -do groups in -dl form. The middle two lines and the last line are ordinary -bu buttons. The "Item A"..."Item D" elements are from -iv shell-variable items.
The first and last commands in the menu each produce the same two error messages:
/bin/bash: -c: line 0: unexpected EOF while looking for matching `'' /bin/bash: -c: line 1: syntax error: unexpected end of file(on a Linux system with /bin/sh linked to /bin/bash).
These error messages are mentioned in the "Dealing with errors in shell commands" subsection of the "DIAGNOSTICS, WARNINGS, CAVEATS" section of yume(1). The "file" referred to in the error messages is just the command string that yume passed to /bin/sh.
In unquoted shell strings, backslash is an escape character that quotes the character after it. When it appears within a quoted string, backslash most commonly is treated as a literal character: always literal within a string quoted by single-quotes, else literal unless next character is "$", "\", or "`" and sometimes "!". See sh(1).) Thus, in the two commands with errors, the first single-quote matches the one just after the backslash. The text from there to end of line isn't quoted text. The single-quote at end of line begins a new section of quoted text, so sh begins looking for a matching single-quote; but as nothing follows, errors occur.
Note, for further xterm examples, please see test-y-4.
In the above, "drop string on button" means: Left click the button after highlighting or selecting a string of text in some window.
Per note: "um5's HMS button gets a number (of seconds) from the clipboard, via "xclip -o". It displays the number of minutes, hours, or days that the number equals. um5's Factor button gets a number (or numbers) from the clipboard, via "xclip -o". It displays the factors of the number(s)."
For example, if you select text 12000 and click HMS, the following will display:
12000 seconds = 200.0 minutes = 3.33 hours = .13 daysor if you click Factor,
12000: 2 2 2 2 2 3 5 5 5The note shows some more examples. dc is a reverse-polish arbitrary precision calculator. The H:M:S script embeds four dc command sequences within
echo "$S seconds = `$D"60 1$E"` minutes = `$D"3600 2$E"` hours = `$D"86400 2$E"` days"'where E="k${S}r/p" and D="/usr/bin/dc -e ". In the example with S=12000, the first dc calculation
`$D"60 1$E"`expands to
/usr/bin/dc -e "60 1k12000r/pwhich pushes 60; pushes 1; k pops 1 and sets precision to 1 digit; pushes 12000; r reverses 60 and 12000; / divides 12000 by 60; p prints result, 200.0. And so forth.
Per note: "When you drop an IP number or internet machine name on the Host/Whois/Dig button, the script puts the IP number into shell variable IP, then in turn invokes host, whois, and dig to get data about the IP number. Output from each command is filtered by grep -v commands, to suppress some uninteresting, repetitive stuff."
wordexp-vals illustrates use of shell Special Parameter expressions $@, $*, $#, $?, $-, $$, $!, and $0 with yume. If your menus do not use any of these expressions, this example will not be relevant.
Some parts of the following discussion require familiarity with the "Special Parameters" subsection of the "PARAMETERS" section of sh(1).
wordexp-vals contains a yume command
like yume -in wordexp-in
, where wordexp-in
is a file with yume-parameter entries to make a menu as above (shown
2/3 scale). For each of the seven shell special parameter
expressions $*, $#, $?, $-, $$, $!, and $0, wordexp-in
contains a variant of the sequence
-bu '%%echo Cash Zero is $0' "%%echo Cash Zero is $0"with appropriate substitutions for each special parameter other than $0.
Thus, the menu contains seven lines with a pair of buttons on each line and each button label is the same as the command string it executes. For each left button, the button's command is single-quoted (so the special parameter expands at button run time rather than yume run time), while for each righthand button, the button's command is double-quoted (so the special parameter expands only at yume run time). The menu also has a one-button line for $@ and an exit button.
For $0, the left button will display [if /bin/sh is linked to /bin/bash]
Y3: echo Cash Zero is $0 Cash Zero is /bin/bashwhile the righthand button will display
Y4: echo Cash Zero is yume Cash Zero is yumeAs noted in yume(1) and yume-meta(1), the %% meta-mode tells yume to print button's command on stdout each time before the command is executed. The number between "Y" and ":" is the internal data structures index number of the button's command.
This example is less complete than it should be, as it doesn't illustrate button-run-time differences between single- and double-quoted instances of $* and $@, nor does it illustrate values when %- or %: meta-mode is used. In these non-shell meta-mode cases, wordexp [see wordexp(3)] is used to expand shell variables before command invocation.
The menu presented by xterms-w-sh contains
do:
blocks with commands like those shown
in test-y-4. Some differences between these
examples are:
Other meta-mode examples include date-of-file, test-y-2, and test-y-4.
A primary reason for yume-examples existing is to allow running examples without needing to cd to yume's examples/ before starting an example-starter. Start yume-examples via a command like
yume-examples yume/examples/-- that is, use a parameter to specify the location of examples/.