[net.unix-wizards] "redo" command revisted

crh (09/03/82)

A while back there was some discussion in this group about a "redo" command
that allowed you to edit a previous command from the history stack using "ex"
in open mode, and then execute the edited command.  I tried the suggested
alias, but it did not work properly for events that had pipe symbols. The
only way the command could be used for such events was to type ":q" as part
of the event specifier, which could be error prone as well as more
keystrokes.  As long as the history substitution takes place on the command
line, there doesn't seem to be any way around this. Putting the q
modifier in the alias is ineffective.

Anyway, I hacked a bit, and found a cute way around this, which my associates
have urged me to share with the net. The trick I use is to specify the event
without the "!", have the redo command put it into a command file with the
appropriate ":q", and then "source" the command file. In short, by defering
the aliasing, we don't have to type ":q" or even the "!". I also incorporated
someone's suggestion (I'm sorry I cant remember who; that person was also
kind enough to mail me a copy of typein) to use a version of "typein" to
enter the command into the tty input buffer, so that the new command will be
entered into the history stack. By putting the "ex' command and the typein
command in the file that gets 'sourced', these *don't* clutter up the history
stack; only the redo command and the edited command get put in. As a final
cute trick, the redo stuff is aliased to '!', so that one uses the mechanism
just like the usual history mechanism except that there is a blank after the
"!". Note that no modifiers can be given though.

If anyone is interested, I will post to net.sources.