If you're trying to find out how xmh uses MH commands so that you can change the way commands work without causing problems, try the techniques in this section.
% xmh -xrm '*debug:1' # 4 : /u/ehuser/.mh_profile # 4 : <Closed> # 4 : /u/ehuser/.xmhcheck # 4 : <Closed> Making screen ... Realizing... done. setting toc ... # 4 : /u/ehuser/Mail/inbox/.xmhcache # 4 : <Closed> # 4 : /u/ehuser/Mail/inbox/.mh_sequences # 4 : <Closed> done. (Checking for new mail... done) (Checking for new mail... done) ...etc.... [magic toc check ... done] ...etc.... (Checking for new mail... done) [magic toc check ...# 4 : /u/ehuser/Mail/inbox/.xmhcache # 4 : <Closed> Executing scan ... pid=13898 blocking. unblocked; child not done. reading alternate input...read. blocking. unblocked; child not done. reading alternate input...read. done # 4 : /u/ehuser/Mail/inbox/.xmhcache # 4 : <Closed> # 4 : /u/ehuser/Mail/inbox/.mh_sequences # 4 : <Closed> done]Here's some brief explanation:
% lastcomm ehuser scan ehuser ?? 0.23 secs Wed Jul 18 09:10 sortm ehuser ?? 0.48 secs Wed Jul 18 09:10 xwud ehuser ttyp1 0.45 secs Wed Jul 18 08:48 ...Unfortunately, lastcomm doesn't show what command-line switches were used or what was in the command's environment as it ran. The next section can help with that.
The idea is to make a directory full of symbolic links to all the MH programs. Tell xmh to use that directory by adding it to your path or setting the MhPath resource. Then, when you want to see or change how xmh uses an MH command, replace the symbolic link with a shell script. The shell script can write log messages to a file, display command-line options that xmh called it with, and execute the MH command. The steps are explained in the next section.
CAUTION: With a radical change like this, there's always the chance of making a mistake that loses or corrupts your mail. If you use xmh for reading important email, I don't recommend this method unless you're very comfortable with UNIX and shell programming.
Making the MhPath Directory, Making xmh Use It
Here are the steps you need to follow to set up the MhPath directory. You only need to do this once.
% ln -s /usr/local/mh/* $HOME/xmhbin % cd $HOME/xmhbin % ls -l lrwxrwxrwx 1 ehuser 17 Jul 15 09:37 ali -> /usr/local/mh/ali lrwxrwxrwx 1 ehuser 18 Jul 15 09:37 anno -> /usr/local/mh/anno ...xmh doesn't actually use all of the MH commands, so you could probably omit some of those links. There's a list of MH commands used at the end of your online xmh(1) manual page.
% foreach prog (ali anno burst ...) ? ln -s /usr/local/bin/$prog ? endThe Sections Sorting Messages: sortm and A Test Mail Setup have more information on shell loops.
% xmh -xrm "*MhPath:$HOME/xmhbin" &The double quotes (") around the -xrm string let the shell replace $HOME with its value. If you put the MhPath entry in a resource file such as .Xdefaults which isn't read by a shell, you'll need to use the literal pathname of the directory (like /xxx/you/xmhbin).
% set path=($HOME/xmhbin $path) % xmh &
Replace a Link with a Shell Script
The next step is to replace a link with a front-end shell script. First, rename the link (or remove it):
% pwd /xxx/yyy/xmhbin % mv sortm sortm.origHere's a simple shell script for sortm. It writes a lot of information to a log file in your home directory, then executes the MH command:
#! /bin/sh # sortm - front end to MH sortm command, run from xmh # appends logging information to $HOME/sortm.log first # use subshell to gather all command output, stdout and stderr: (date echo "args are: $0 $*" echo "environment has:" printenv) >> $HOME/sortm.log 2>&1 # run the real command with exec, so this script # (and the shell that runs it) can exit now: exec /usr/local/mh/sortm $*After you've installed the script, try it (in this case, use the Sort Folder command). The sortm.log file in your home directory should look something like this:
% cat $HOME/sortm.log Wed Jul 18 10:12:46 EDT 1990 args are: /xxx/you/xmhbin/sortm +/xxx/you/Mail/inbox -noverbose environment has: DISPLAY=unix:0.0 EDITOR=/usr/ucb/vi HOME=/xxx/you ...and, of course, your current folder should have been sorted.
Standard Output vs. Standard Error
If your shell script writes any messages to the standard output, xmh may ignore them. Or, in cases where xmh is expecting to read useful information on the standard output, xmh could accidentally include what your script writes to the standard output. For example, when you Rescan Folder, xmh runs scan and puts the scan standard output into the .xmhcache file.
xmh Release 4 added a nice new feature: if a command writes a message to the standard error, the message is displayed in a notice box. Your script can use this feature to send you messages. As a semi-useless but easy to understand example, here's a version of pick that shows the command-line options xmh uses:
#! /bin/sh echo "pick arguments are: $*" | fmt -50 1>&2 exec /usr/local/mh/pick ${1+"$@"}The fmt -50 command folds lines at whitespace to keep the box width reasonable. If you don't have fmt, try fold instead. The ${1+"$@"} works around a problem with command-line parameters in sme older Bourne shells. I ran that pick front-end with search shown in the Figure Example of Pick skip button. The window I got after pick finishes is shown in the Figure below. (It makes me glad I did that with an xmh Pick window instead of typing the MH pick command myself.)
I don't recommend using xmh notice boxes for commands that make a lot of output. I'd bet that they weren't really designed for this sort of abuse....
NOTE: xmh Release 3 isn't happy about unexpected output and doesn't make the nice notice boxes. Use a log file instead.
[Table of Contents] [Index] [Previous: Changing the Print Command] [Next: Chapter Introduction (Tour Through mh-e)]
This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.
Suggestions are welcome: Jerry Peek <jerry@ora.com>
HIVE: All information for read only. Please respect copyright! |