Wanted: thoughts about history mechanisms.

Alex Martelli alex at am.sublink.org
Fri Apr 26 07:24:31 AEST 1991


I've also hacked a simple mechanism into ash for history processing
via external commands (mostly for Minix and Coherent, actually); the
credit for the idea must go, at least 3/4ths of it, to my friend and
colleague Lanfranco Albani, albani at cadlab.sublink.org, although I was
the one that did most of the implementation.
1. the shell just appends each logical-line to a history-file; this is
   how any history-like external command accesses the history;
2. if, when the shell is about to emit a primary-prompt to terminal, it
   finds that a file named $HOME/..dothis exists, it opens, unlinks, 
   and then sources it; this is how the shell accesses the results of
   any history-like external command.

Several enhancements suggest themselves (have both history-file and
doit-file named by environment variables, and so on) - and the best
thing is that, far from needing 8K of codespace, both of these changes
will fit in just a few bytes... another one of this class, if you like
csh-like history-expansion as well as interactive one, is to have an
environment variable HISTORY-WHEN whose syntax is a colon-separated
list of pairs regular-expression//program-name: if a logical line
matches a regular expression, then it is passed to the standard input
of the associated program name (at a quite early stage of the 
processing) - the program can emit the commands to be performed to
standard output and/or to the doit-file as before.
For example, an HISTORY-WHEN of '/^^|[^\\]!/cshclone' would strictly
imitate csh's behavior (assuming cshclone does so) - the /'s are just
arbitrary separators, the regular expression means 'a caret at line
start or a non-backslash followed by a bang' (...the heavy overloading
of the caret sign makes it LOOK more complex that it is...:-).
As you can probably tell, this last suggestion is one I have not 
implemented, nor even fully finalized in design [what exactly should
be the difference between the history-filter emitting to stdout versus
putting commands into the doit-file, and what if it does both, what
*should* be put into the history-file, etc, to keep it reasonably
simple and usable].  Notice that ash already has regexps, as a part
of the expr/test builtin, so their price in codesize has been paid
already...

As is typical of good ideas, these simple tricks have many uses - the
doit-file, for example, allows not only history-like mechanisms but
all sorts of external mechanisms able to set the shell's environment,
change its current-directory, and so on.
Together with the "executable prompt string" that we already 
discussed, these ideas work well in my ash ('mash').  I would of
course be honored if any shell author felt it worth his or her while
to use or elaborate them in another shell... 
-- 
Alex Martelli - (home snailmail:) v. Barontini 27, 40138 Bologna, ITALIA
Email: (work:) martelli at cadlab.sublink.org, (home:) alex at am.sublink.org
Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; 
Fax: ++39 (51) 366964 (work only), Fidonet: 332/401.3 (home only).



More information about the Comp.unix.shell mailing list